home *** CD-ROM | disk | FTP | other *** search
/ ETO Development Tools 2 / ETO Development Tools 2.iso / Tools - Objects / MacApp / MacApp CD Release / MacApp 2.0.1 (Many Libraries) / Interfaces / CIncludes / UMacApp.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-25  |  190.3 KB  |  3,999 lines  |  [TEXT/MPS ]

  1. /*[a-,body+,h-,o=100,r+,rec+,t=4,u+,#+,j=20/57/1$,n-]*/ /* Pasmat format control line */
  2. /* UMacApp.p */
  3. /* Copyright © 1984-1990 by Apple Computer Inc.  All rights reserved. */
  4.  
  5. /* ??? Comments that contain '???' (such as this one) indicate issues that need
  6.  to be resolved sooner or later. ???
  7.  The MacApp® team wishes to thank MADA, Carl Nelson, Robin Mair and Jeff Alger for
  8.  generously allowing us to us the MADA MacApp 2.0 Condensed reference text freely.
  9.  This has allowed us to document a number of "historical" interfaces.  */
  10. #ifndef  __UMacApp__
  11. #define __UMacApp__  0
  12. #endif
  13. #if  ! __UMacApp__
  14. #define __UMacApp__  1
  15.  
  16.         /* • Required for this unit's interface. Auto-Include them */
  17. #ifndef  __UMacAppUtilities__
  18. #include "UMacAppUtilities.h"
  19. #endif
  20. #ifndef  __UObject__
  21. #include "UObject.h"
  22. #endif
  23. #ifndef  __UList__
  24. #include "UList.h"
  25. #endif
  26. #ifndef  __UAssociation__
  27. #include "UAssociation.h"
  28. #endif
  29. #ifndef  __UFailure__
  30. #include "UFailure.h"
  31. #endif
  32. #ifndef  __UPatch__
  33. #include "UPatch.h"
  34. #endif
  35. #ifndef  __UMemory__
  36. #include "UMemory.h"
  37. #endif
  38. #ifndef  __UMenuSetup__
  39. #include "UMenuSetup.h"
  40. #endif
  41. #ifndef  __UViewCoords__
  42. #include "UViewCoords.h"
  43. #endif
  44. #ifndef  __SCRAP__
  45. #include "Scrap.h"
  46. #endif
  47. #ifndef  __WINDOWS__
  48. #include "Windows.h"
  49. #endif
  50. #ifndef  __DIALOGS__
  51. #include "Dialogs.h"
  52. #endif
  53.  
  54. const unsigned char kCopyright[]          =
  55. "\pMacApp® 2.0.1 Copyright © 1984-1990 Apple Computer, Inc.  All rights reserved."
  56. ;
  57.  
  58.             /* M E N U S */
  59. const short kMBarDisplayed        = 128;                    /* Default 'MBAR' id of the menus that are
  60.                                                          read in and installed in menu bar */
  61. const short kMBarNotDisplayed    = 129;                    /* Default 'MBAR' id of the menus that are
  62.                                                          read in but not installed */
  63. const short kMBarHierarchical    = 130;
  64.    /* Default 'MBAR' id of the menus that pop up
  65.                                                          when a menu item is choosen */
  66.  
  67.             /* C O M M A N D S */
  68.  
  69.             /* Negative numbers and positive numbers up to 999 are reserved by MacApp */
  70.             /* Predefined command numbers ??? Renumber these more logically ??? */
  71.             /* Not all of these are caught by MacApp.
  72.             "<!>" means MacApp catches it.
  73.             "<&>" means TEView catches it.
  74.             "<->" means the application must catch it if it is used as a
  75.             command number in any menu."
  76.             {Special command codes */
  77.  
  78. const short cNoCommand            = 0;
  79.    /* <!> Command number representing no command
  80.                                                          */
  81. const short cCantUndo            = - 1;                    /* <!> Passed to TApplication.SetUndoText to
  82.                                                          indicate that the command cannot be
  83.                                                          undone. */
  84.  
  85.             /* Apple-menu commands */
  86.  
  87. const short cAboutApp            = 1;                    /* <!> "About <appname>…" */
  88.  
  89.             /* File-menu filing commands */
  90.  
  91. const short cNew                = 10;                    /* <!> "New" (??? reserve a range of NEW
  92.                                                          commands ???) */
  93. const short cNewLast            = 19;
  94. const short cOpen                = 20;                    /* <!> "Open …" (??? reserve a range of OPEN
  95.                                                          commands ???) */
  96. const short cOpenLast            = 29;
  97.  
  98. const short cSave                = 30;                    /* <!> "Save" */
  99. const short cClose                = 31;                    /* <!> "Close" */
  100. const short cSaveAs                = 32;                    /* <!> "Save as…" */
  101. const short cSaveCopy            = 33;                    /* <!> "Save a Copy in …" */
  102. const short cRevert                = 34;                    /* <!> "Revert" (to previous version) */
  103. const short cShowClipboard        = 35;                    /* <!> "Show Clipboard"/"Hide Clipboard" */
  104. const short cQuit                = 36;                    /* <!> "Quit" */
  105.  
  106.             /* Edit-menu commands */
  107.  
  108.             /* For the following command numbers, we must guarantee that
  109.             <command number> - cEditBase = <appropriate number to pass to
  110.             SystemEdit>.  This relationship is enforced in
  111.             TApplication.IApplication. */
  112. const short cEditBase            = 101;                    /* start of standard editing commands */
  113. const short cUndo                = 101;                    /* <!> "Undo <command>"/"Redo <command>" */
  114. const short cEditSep            = 102;                    /* line separating UNDO from CUT */
  115. const short cCut                = 103;                    /* <&> "Cut" */
  116. const short cCopy                = 104;                    /* <&> "Copy" */
  117. const short cPaste                = 105;                    /* <&> "Paste" */
  118. const short cClear                = 106;                    /* <-> "Clear" */
  119. const short cEditLast            = cClear;
  120.  
  121. const short cSelectAll            = 110;                    /* <&> "Select All" */
  122.  
  123. const short cTyping                = 120;                    /* for use in a TTypingCommand */
  124. const short cMouseCommand        = 121;                    /* generic mouse command */
  125.  
  126. const short cStyleChange        = 130;                    /* "Menu" command for style change */
  127. const short cRememberStyle        = 131;                    /* "Menu" command for remembering present
  128.                                                          style */
  129.  
  130.             /* Finder pseudo-commands */
  131.  
  132. const short cFinderNew            = 40;
  133.    /* <!> The user selected the tool icon in the
  134.                                                          Finder and chose "Open" */
  135. const short cFinderPrint        = 41;                    /* <!> The user selected document icons in
  136.                                                          the Finder and chose "Print" */
  137. const short cFinderOpen            = 42;                    /* <!> The user selected document icons in
  138.                                                          the Finder and chose "Open" */
  139.  
  140.             /* File-menu printing commands  */
  141.  
  142. const short cPrFileBase            = 176;                    /* Command numbers between cPrFileBase and
  143.                                                          cPrFileMax are sent to a document's
  144.                                                          fDocPrintHandler even if it is not in the
  145.                                                          fTarget chain */
  146. const short cPrFileMax            = 195;
  147.  
  148. const short cPageSetup            = 176;                    /* <!> "Page Setup…" */
  149. const short cPrintOne            = 177;                    /* <!> "Print One" */
  150. const short cPrint                = 178;                    /* <!> "Print…" */
  151. const short cPrintToFile        = 179;                    /* <!> "Print to file…" */
  152.  
  153. const short cPrintSpoolFile        = 190;                    /* <-> "Print spooled file…" */
  154.  
  155. const short cPrViewBase            = 201;                    /* Command numbers between cPrViewBase and
  156.                                                          cPrViewMax are printing commands applied
  157.                                                          to a displayed view in the fTarget chain */
  158. const short cPrViewMax            = 250;
  159.  
  160. const short cShowBorders        = 199;                    /* <!> Toggle. "Show view borders"--also
  161.                                                          usable outside Debug menu */
  162.  
  163.             /* Zooming commands */                        /* Not being used at present */
  164.  
  165. const short cReduce50            = 301;                    /* <-> "Reduce 50%" */
  166. const short cReduceToFit        = 302;                    /* <-> "Reduce to Fit" */
  167. const short cShowFullSize        = 303;                    /* <-> "Show Full Size" */
  168.  
  169.             /* Control tracking */
  170. const short cTrackingControl    = 400;
  171.  
  172.             /* Debug-menu commands.  Flag toggled by "cFoo" is called "gFoo" for any
  173.             "Foo" */
  174.  
  175. const short cIdentifySoftware    = 900;                    /* <!> Action. "Show Software Version"--
  176.                                                          WriteLn version info */
  177. const short cExperimenting        = 901;
  178.    /* <!> Toggle. "Enable experimental features"
  179.                                                          */
  180. const short cReportMenuChoices    = 902;                    /* <!> Toggle. "Trace menu commands"--
  181.                                                          WriteLn menu choices */
  182. const short cIntenseDebugging    = 904;                    /* <!> Toggle. "Intense Debugging" */
  183. const short cTraceSetupMenus    = 905;                    /* <!> Toggle. "Allow Trace of Menu Setups"
  184.                                                          if gTrace is also on */
  185. const short cTraceIdle            = 906;                    /* <!> Toggle. "Allow Trace during Idle" if
  186.                                                          gTrace is also on */
  187. const short cDebugPrinting        = 912;                    /* <!> Toggle. "Debug Printing" */
  188. const short cReportEvt            = 914;                    /* <!> Toggle. "Report Events"--WriteLn
  189.                                                          events received from queue */
  190. const short cDoFirstClick        = 915;                    /* <!> Toggle. "'Do First Click' for this
  191.                                                          window" */
  192. const short cVarClipPicSize        = 916;                    /* <!> Toggle. "Scale Pictures in Clipboard
  193.                                                          to Window" */
  194. const short cRefreshFrontWindow = 917;                    /* <!> Action. "Refresh Front Window" */
  195. const short cNewInspectorWindow = 918;
  196.    /* <!> Action. "Open new inspector window" */
  197. const short cModalToggle        = 919;                    /* <!> Toggle. "Make front window
  198.                                                          modal/modeless"*/
  199. const short cDebugWind            = 913;                    /* <!> Action. "Show Debug Window" */
  200. const short cEnterMacAppDebugger = 920;
  201.    /* <!> Action. "Enter the MacApp Debugger" */
  202.  
  203. const short cSetSysJust            = 921;
  204.    /* <!> Action. "Switch system justification" */
  205.  
  206.  
  207.             /* D E B U G  F L A G S */
  208.  
  209. #if  ! qDebug                                            /* These start with 'g' because they are
  210.                                                          global variables when qDebug is TRUE */
  211. const short gExperimenting        = false;
  212. const short gReportMenuChoices    = false;
  213. const short gIntenseDebugging    = false;
  214. const short gDebugPrinting        = false;
  215. const short gReportEvt            = false;
  216.  
  217. const short gMemMgtReport        = false;
  218. const short gAssumeFocused        = false;
  219. #endif
  220.  
  221.             /* A L E R T S */
  222.  
  223. const short errReasonID            = 128;                    /* resource ID of errs resource describing
  224.                                                          error messages */
  225. const short errRecoveryID        = 129;                    /* resource ID of errs resource describing
  226.                                                          recovery messages */
  227. const short errOperationsID        = 130;                    /* resource ID of errs resource containing
  228.                                                          operation strings */
  229. const short errAppTable            = 1000;
  230.    /* added to the MacApp resource ID to get the
  231.                                                          ID of an application error table */
  232.  
  233. const short msgCmdErr            = 0;                    /* when added to a command number, gives a
  234.                                                          message value to display the alert "Could
  235.                                                          not complete the … command …" */
  236. const long msgAlert               = 0xFFFF0000;            /* when added to an alert number, gives a
  237.                                                          message value to display that alert */
  238. const long msgLookup           = 0xFFFE0000;            /* when added to an INTEGER, gives a message
  239.                                                          value that will look up the INTEGER in
  240.                                                          table errOperationsID and display the
  241.                                                          alert "Could not … because …" */
  242. const long msgAltRecovery       = 0xFFFD0000;            /* same as msgLookup, except the INTEGER is
  243.                                                          used instead of the error number to lookup
  244.                                                          the recovery string */
  245.  
  246. const long msgStrList           = 130 * 0x10000;
  247.    /* Standard list of operation strings used by
  248.                                                          MacApp * $10000 to plunk it into hiwrd */
  249. const long msgCancelled           = msgStrList;            /* used with error = noErr if user cancels
  250.                                                          Save, Quit, … */
  251. const long msgInitFailed       = msgStrList + 1;
  252. const long msgSaveFailed       = msgStrList + 2;
  253. const long msgRevertFailed       = msgStrList + 3;
  254. const long msgPrintFailed       = msgStrList + 4;
  255. const long msgNewFailed           = msgStrList + 5;
  256. const long msgOpenFailed       = msgStrList + 6;
  257. const long msgSaveAsFailed       = msgStrList + 7;
  258. const long msgSaveCopyFailed   = msgStrList + 8;
  259. const long msgDrawFailed       = msgStrList + 9;
  260. const long msgImportClipFailed = msgStrList + 10;
  261. const long msgExportClipFailed = msgStrList + 11;
  262.  
  263.             /* error codes used in MacApp; applications should use errors between
  264.             -25000 and -29999 */
  265.  
  266. const short errSpooling            = - 20000;                /* print spooling failed OSErr */
  267. const short errRevertFNF        = - 20001;                /* Revert failed because file was deleted */
  268. const short errFileChanged        = - 20002;                /* disk file modification date changed */
  269. const short errSaveAgain        = - 20003;                /* Save As / Save a Copy in an opened
  270.                                                          document */
  271. const short errFTypeChanged        = - 20004;                /* disk file type changed */
  272. const short errNoPrintDrvr        = - 20005;                /* print driver file not found */
  273. const short errNotMyType        = - 20006;                /* can't open this file type */
  274. const short errNotImplemented    = - 20007;                /* Signaled when a function is not yet
  275.                                                          implemented */
  276. const short errMissingClass        = - 20008;                /* Signaled when a class is missing. Usually
  277.                                                         due to failure to dead-strip suppress when
  278.                                                         creating objects any other way than by "NEW" */
  279.  
  280.             /* Alerts 0 - 249 are reserved by MacApp. */
  281.  
  282. const short phGenError            = 128;                    /* 'Could not ^2, because ^0. ^1' */
  283. const short phCmdErr            = 129;                    /* 'Could not complete the “^2” command
  284.                                                          because ^0. ^1'. */
  285. const short phUnknownErr        = 130;                    /* 'Could not complete your request because
  286.                                                          ^0. ^1'; only used if no operation is
  287.                                                          supplied. */
  288. const short phSaveChanges        = 131;                    /* 'Save Changes Before Closing?' */
  289. const short phRevert            = 132;                    /* 'Revert to last version saved?' */
  290. const short phFileChanged        = 133;                    /* 'File changed since last save.' */
  291. const short phPurgeOld            = 134;
  292.    /* 'OK to purge old version before saving new
  293.                                                          one?' */
  294. const short phReopenDoc            = 135;                    /* 'Document is already open.' */
  295. const short phSpaceIsLow        = 136;                    /* 'Space is low' */
  296. const short phUnsupportedConfiguration = 137;            /* 'Can't start app because your machine is
  297.                                                          too wimpy!' */
  298. const short phOfferReadOnly        = 138;                    /* 'Can't open for file for write. Open
  299.                                                          read-only?' */
  300.  
  301. const short phTooManyChars        = 150;                    /* 'Too Many Characters', used to reject
  302.                                                          paste or keystrokes in UDialog and UTEView
  303.                                                          */
  304.  
  305. const short phStylesTooBig        = 151;                    /* 'Too Many Styles', used to reject the
  306.                                                          styles portion of a paste in UTEView */
  307.  
  308. const short phAboutApp            = 201;
  309.    /* Can hold the 'About <appName>…' message */
  310.  
  311. const short phUnimplemented        = 202;                    /* 'This feature not yet implemented' */
  312.  
  313.             /* M A C A P P   B U Z Z - S T R I N G   R E S O U R C E */
  314. const short kIDBuzzString        = 250;                    /* std list of buzzwords stored as 'STR#'
  315.                                                          resources. This string list is reserved
  316.                                                          for MacApp; you should choose a different
  317.                                                          resource ID for your strings. */
  318.  
  319.             /* Indices for strings in the buzz-string resource */
  320. const short bzSaveAs            = 1;                    /* 'Save This Document As:' */
  321. const short bzSaveCopy            = 2;                    /* 'Save a Copy In:' */
  322. const short bzShowClip            = 3;                    /* 'Show Clipboard' */
  323. const short bzHideClip            = 4;                    /* 'Hide Cllpboard' */
  324. const short bzUndo                = 5;                    /* 'Undo x' */
  325. const short bzRedo                = 6;                    /* 'Redo x' */
  326. const short bzCantDraw            = 7;                    /* 'Unable to draw contents of window' */
  327. const short bzUntitled            = 8;                    /* name of untitled document; if blank then
  328.                                                          this is taken from the window title
  329.                                                          template; if this includes the string
  330.                                                          '<<<>>>' then MacApp will substitute a
  331.                                                          number for the string (e.g., if the buzz
  332.                                                          string contains 'Untitled-<<<>>>' then
  333.                                                          untitled windows will be named
  334.                                                          'Untitled-1', Untitled-2, … */
  335. const short bzClosing            = 9;                    /* 'closing' */
  336. const short bzQuitting            = 10;                    /* 'quitting' */
  337. const short bzCantUndo            = 11;                    /* 'Can’t Undo' */
  338. const short bzSaveAnyways        = 12;                    /* 'save' */
  339. const short bzRevertAnyways        = 13;                    /* 'revert' */
  340.  
  341.             /* D E B U G   B U Z Z - S T R I N G   R E S O U R C E */
  342. const short kDebugBuzzStrings    = 251;                    /* Debug buzzwords STR# resource */
  343. const short bzMakeModal            = 1;                    /* 'Make Front Window Modal' */
  344. const short bzMakeModeless        = 2;                    /* 'Make Front Window Modeless' */
  345. const short bzDoFirstClick        = 3;                    /* 'Do First Click For This Window' */
  346. const short bzDontDoFirstClick    = 4;                    /* 'Don't Do First Click For This Window' */
  347. const short bzSetRightSysJust    = 5;                    /* Set system to right justification */
  348. const short bzSetLeftSysJust    = 6;                    /* Set system to left justification */
  349.  
  350.             /* R E S O U R C E   I D S */
  351.             /* Negative numbers and numbers up to 127 are reserved by Apple */
  352.             /* Positive numbers from 128 up to 999 are reserved by MacApp */
  353. const short kDefaultCredits        = 1001;                    /* People responsible for the application */
  354. const short kIDClipWindow        = 200;                    /* window displaying the Clipboard */
  355. const short kScrollBarId        = 202;                    /* for when we create scrollers from
  356.                                                          resources */
  357. const short kDebugParamsID        = 300;                    /* debug window */
  358.  
  359.             /* V I E W   I D E N T I F I E R S */
  360.             /* These follow the same reservation rules as resource types */
  361.  
  362. const short kDefaultWindowID    = 1001;                    /* Window view resource installed by default
  363.                                                          in TDocument */
  364. const short kDefaultViewID        = 1002;                    /* View resource installed by default in
  365.                                                          TDocument */
  366. const unsigned long kIDDefaultView        = 'DFLT';        /* View ID of default view */
  367. const unsigned long kIDClipView            = 'CLIP';        /* identifier of the clipboard "orhanage" */
  368.  
  369.             /* O B J E C T  S I G N A T U R E S */
  370.             /* These follow the same reservation rules as resource types */
  371.             /* The signature is used to search the signature table and create
  372.             an object "by signature"  If the signature's entry in the table has
  373.             been updated with a new class then an object of that class will be created. */
  374.  
  375. const unsigned long kStdDocument        = 'docu';
  376. const unsigned long kStdTracker            = 'trak';
  377. const unsigned long kStdList            = 'list';
  378.  
  379. const unsigned long kStdButton            = 'butn';
  380. const unsigned long kStdCheckBox        = 'chkb';
  381. const unsigned long kStdCluster            = 'clus';
  382. const unsigned long kStdControl            = 'cntl';
  383. const unsigned long kStdDefaultView        = 'dflt';
  384. const unsigned long kStdDialogView        = 'dlog';
  385. const unsigned long kStdEditText        = 'edit';
  386. const unsigned long kStdGridView        = 'grid';
  387. const unsigned long kStdIcon            = 'icon';
  388. const unsigned long kStdNumberText        = 'nmbr';
  389. const unsigned long kStdPattern            = 'patn';
  390. const unsigned long kStdPicture            = 'pict';
  391. const unsigned long kStdPopup            = 'popp';
  392. const unsigned long kStdRadio            = 'radb';
  393. const unsigned long kStdScroller        = 'scrl';
  394. const unsigned long kStdSScrollBar        = 'sbar';
  395. const unsigned long kStdStaticText        = 'stat';
  396. const unsigned long kStdTEView            = 'tevw';
  397. const unsigned long kStdTextGridView    = 'txtg';
  398. const unsigned long kStdTextListView    = 'lstg';
  399. const unsigned long kStdView            = 'view';
  400. const unsigned long kStdWindow            = 'wind';
  401.  
  402.             /* H I G H L I G H T I N G */
  403. const short hlOff                = 1;                    /* the selection is to be unhighlighted */
  404. const short hlDim                = 2;
  405.    /* the selection is to be dimly highlighted */
  406. const short hlOn                = 4;
  407.    /* the selection is to be fully highlighted */
  408.  
  409.             /* these constants can be used to test for combinations of fromHL+toHL,
  410.  
  411.             when you do not care which is from and which is to */
  412. const short hlOffDim            = hlOff + hlDim;
  413. const short hlDimOff            = hlOffDim;
  414. const short hlDimOn                = hlDim + hlOn;
  415. const short hlOnDim                = hlDimOn;
  416. const short hlOffOn                = hlOff + hlOn;
  417. const short hlOnOff                = hlOffOn;
  418.  
  419.             /* C H O I C E S */
  420.  
  421.             /* Negative numbers and positive numbers up to 999 are reserved by MacApp */
  422. const short mOKHit                = 1;
  423. const short mCancelHit            = 2;
  424. const short mButtonHit            = 3;
  425. const short mCheckBoxHit        = 4;
  426. const short mClusterHit            = 5;
  427. const short mEditTextHit        = 6;
  428. const short mIconHit            = 7;
  429. const short mListItemHit        = 8;
  430. const short mListScrollBarHit    = 9;
  431. const short mPictureHit            = 10;
  432. const short mPopupHit            = 11;
  433. const short mRadioHit            = 12;
  434. const short mStaticTextHit        = 13;
  435. const short mHScrollBarHit        = 14;
  436. const short mVScrollBarHit        = 15;
  437. const short mEditTabKey            = 16;
  438. const short mEditReturnKey        = 17;
  439. const short mEditEnterKey        = 18;
  440. const short mPatternHit            = 19;
  441. const short mControlHit            = 20;
  442. const short mCancelKey            = 21;
  443. const short mDefaultKey            = 22;
  444.  
  445. const unsigned long kNoIdentifier        = '    ';
  446. const short kNoTemplate            = - 1;
  447. const short kNoResource            = - 1;
  448.  
  449.             /* M I S C E L L A N E O U S */
  450. const unsigned long kStdMainFileType    = 'TEXT';
  451.    /* the file type identifier used by default */
  452.  
  453. const short kYesButton            = 1;                    /* the 'Yes' button in various dialogs */
  454. const short kNoButton            = 3;                    /* the 'No' button in various dialogs */
  455.  
  456. const short kLowSpaceInterval    = 2 * 60 * 60;
  457.    /* default low space msg interval (2 seconds)
  458.                                                          */
  459.  
  460. const short kStdScrollUnit        = 16;                    /* default value of fScrollUnit used by
  461.                                                          scrollers */
  462.  
  463. const short kSBarSize            = 16;
  464. const short kSBarSizeMinus1        = kSBarSize - 1;
  465.             /* !!! Prefer the above names */
  466. const short kStdSzSBar            = 16;                    /* width/height of a standard
  467.                                                          vertical/horizontal scroll bar */
  468. const short kStdSzMinus1SBar    = kStdSzSBar - 1;
  469.  
  470. const short kStdStaggerAmount    = 16;
  471.    /* standard # of pixels to stagger windows */
  472.  
  473. const unsigned long kMaxIdleTime           = LONG_MAX;    /* Default tick count sent to WaitNextEvent */
  474.  
  475.             /* Numbers to pass to SystemEdit */
  476. const short kSysUndo            = 0;
  477. const short kSysCut                = 2;
  478. const short kSysCopy            = 3;
  479. const short kSysPaste            = 4;
  480. const short kSysClear            = 5;
  481.  
  482. #if  qDebug
  483. const short kRsrcCheckInterval    = 100;
  484. #endif
  485. const short kPriorityLowest        = 127;                    /* Low priority commands are considered last
  486.                                                          */
  487. const short kPriorityLow        = kPriorityLowest - 32; /* Low priority commands are considered last
  488.                                                          */
  489. const short kPriorityNormal        = 64;                    /* Normal priority assigned to commands by
  490.                                                          default */
  491. const short kPriorityHighest    = 0;                    /* High priority commands take precedence */
  492. const short kPriorityHigh        = kPriorityHighest + 32; /* High priority commands take precedence */
  493.  
  494. const short kBuild                = true;                    /* Pass to TWindow.BuildWindowRgns */
  495. const short kAllowApplicationToSleep = true;            /* Pass to TApplication.PollEvent if the
  496.                                                          application is allowed to sleep if there
  497.                                                          are no events pending. */
  498.             /* P R I N T I N G */
  499. const short kSquareDots            = true;                    /* Square dots in Printing */
  500. const short kFixedSize            = true;                    /* Fixed Page Size in Printing */
  501.  
  502. const short kPrintInfoSize        = 120;                    /* size in bytes of printInfo record */
  503.  
  504.             /* size in bytes of the overhead for a resource file;
  505.             kRsrcFileOverhead is added in TDocument.DoNeedDiskSpace if the
  506.             document uses the rsrc fork.
  507.             You should add kRsrcTypeOverhead for each unique type you use
  508.             plus kRsrcOverhead for each resoruce you use
  509.             plus the total bytes in all the resources
  510.             plus the length of all the names for named resources. */
  511. const short kRsrcFileOverhead    = 256 +                    /* resource header & stuff */
  512. 30                                                        /* fixed part of resource map */ ;
  513. const short kRsrcTypeOverhead    = 8;                    /* overhead for each resource type */
  514. const short kRsrcOverhead        = 16;                    /* overhead for each resource */
  515.  
  516.             /* ??? */
  517. const short kViewRsrcExpandAmt    = 0x400;                /* ??? Is 1K enough for expansion, or too
  518.                                                          much maybe??? */
  519.  
  520.             /* debugging info */
  521. const short kDebugFont            =                        /*monaco*/ 4; /* Font for Debug Window */
  522. const short kDebugSize            = 9;                    /* Font size for Debug Window */
  523.  
  524.             /* argument of TDocument.DoMakeViews */
  525. const short kForDisplay            = false;
  526. const short kForPrinting        = ! kForDisplay;
  527.  
  528.             /* arguments of TScroller.IScroller */
  529. const short kWantHScrollBar        = true;
  530. const short kWantVScrollBar        = true;
  531.  
  532.             /* arguments of TDocument.Save */
  533. const short kAskForFilename        = true;
  534. const short kMakingCopy            = true;
  535. const short kSwitchToTarget        = ! kMakingCopy;
  536.  
  537.             /* argument of NewPaletteWindow */
  538. const short kLeftPalette        = h;
  539. const short kTopPalette            = v;
  540.  
  541.             /* argument of TApplication.SetUndoText */
  542. const short kShowUndo            = true;
  543. const short kShowRedo            = false;
  544. const short kShowCantUndo        = kShowUndo;
  545.  
  546.             /* argument of TDocument.IDocument */
  547. const short kUsesDataFork        = true;
  548. const short kUsesRsrcFork        = true;
  549. const short kDataOpen            = true;
  550. const short kRsrcOpen            = true;
  551.  
  552.             /* argument of TDocument.OpenDocFile */
  553. const short kKeepingOpen        = true;
  554. const short kReadingFile        = true;
  555.  
  556. const short kVisible            = true;
  557. const short kInvisible            = false;
  558.  
  559.             /* arguments to routines with a 'redraw' parameter */
  560. const short kRedraw                = true;
  561. const short kDontRedraw            = false;
  562.  
  563.             /* arguments to routines with an 'invalidate' parameter */
  564. const short kInvalidate            = true;
  565. const short kDontInvalidate        = false;
  566.  
  567.             /* MultiFinder event message masks */
  568. const short kSuspendOrResume    = 0x01;
  569. const short kMouseMovedMessage    = 0xFA;
  570.  
  571. const short kMaxSignatures        = 32;
  572.  
  573.             /* E V E N T S */
  574.  
  575. typedef EventRecord *EventRecordPtr;
  576.    /* EventRecord is a ToolBox type. The pointer
  577.                                                          type _MUST_ be declared first since the
  578.                                                          record is self referential */
  579. struct EventInfo {
  580.    /* stores more information about the event in
  581.                                                          an unpacked form */
  582.     EventRecordPtr thePEvent;                            /* pointer to the original packed ToolBox
  583.                                                          event record */
  584.     Boolean theBtnState;                                /* bits found in the modifiers field of an
  585.                                                          EventRecord */
  586.     Boolean theCmdKey;                                    /* Was Command key depressed? */
  587.     Boolean theShiftKey;                                /* Was Shift key depressed? */
  588.     Boolean theAlphaLock;                                /* Was Alpha Lock depressed? */
  589.     Boolean theOptionKey;                                /* Was Option key depressed? */
  590.     Boolean theControlKey;                                /* Was Control key depressed? */
  591.     Boolean theAutoKey;                                    /* TRUE if this was an auto key event */
  592.     short theCharacter;                                    /* IF a key event the char that the event
  593.                                                         translates to !!! what about 16 
  594.    bit chars? */
  595.     short theKeyCode;
  596.        /* IF a key event the virtual key code that the
  597.                                                         event translates to */
  598.  
  599.     short theClickCount;
  600.        /* 0 = event was not a mouse down; 1-N = # of
  601.                                                          multiple clicks */
  602.     Boolean affectsMenus;                                /* True means the menus must be setup after
  603.                                                          the event */
  604. };
  605. typedef EventRecordPtr PEventRecord;                    /* Left in for compatibility (2.0) */
  606.  
  607. typedef enum {idleBegin, idleContinue, idleEnd} IdlePhase;
  608. typedef enum {trackPress, trackMove, trackRelease} TrackPhase;
  609.  
  610.             /* V I E W  C O O R D I N A T E S */
  611.  
  612. typedef enum {sizeSuperView, sizeRelSuperView, sizePage, sizeFillPages, sizeVariable, sizeFixed} 
  613.    SizeDeterminer;
  614.    /* No special default handling of size issues
  615.                                                          */
  616.  
  617.             /* H I G H L I G H T I N G */
  618. typedef unsigned char HLState;
  619.  
  620.             /* D O C U M E N T S */
  621.             /* How to save a document in place, if MacApp decides this is needed.
  622.             sipNever: never save on top of old file (ie., save will fail if
  623.             there is not enough disk space)
  624.             sipAlways: save on top of old file without asking user
  625.             sipAskUser: save on top, but only if user confirms
  626.             */
  627. typedef enum {sipNever, sipAlways, sipAskUser} SIPChoice;
  628.  
  629.             /* O T H E R */
  630. typedef AppFile *AppFilePtr;                            /* AppFile is segment loader section of
  631.                                                          Inside Macintosh */
  632. typedef AppFilePtr PAppFile;                            /* Left in for compatibility (2.0) */
  633.  
  634. typedef OSType ArrTypeList[8000];
  635. typedef ArrTypeList *TypeListPtr;                        /* Preferred */
  636. typedef TypeListPtr *TypeListHandle;                    /* Preferred */
  637. typedef TypeListPtr PTypeList;                            /* Left in for compatibility (2.0) */
  638. typedef TypeListHandle HTypeList;                        /* Left in for compatibility (2.0) */
  639.  
  640. typedef unsigned char CommandPriority;                                 /* Command priorities */
  641.  
  642. class TEvtHandler : public TObject {
  643.   public:            /* The TEvtHandler type represents abstract
  644.                                                          objects that handle certain kinds of
  645.                                                          events: Key events: both key down and auto
  646.                                                          key events, menu events: both enabling
  647.                                                          menus and menu items and processing menu
  648.                                                          commands, Read to/write from Disk, Idle
  649.                                                          events: when there are no other events to
  650.                                                          handle, Actual events: EvtHandlers -
  651.                                                          through their method 'DoHandleEvent' may
  652.                                                          intercept and handle actual ToolBox events
  653.                                                          Termination: when the application quits
  654.                                                          TEvtHandler are linked into a list with
  655.                                                          the most specific object (usually a
  656.                                                          selection) at the head of the list. The
  657.                                                          global variable 'gTarget' contains the
  658.                                                          head of the list. (When a window is
  659.                                                          deactivated, this global variable is
  660.                                                          cached in the window object, and retrieved
  661.                                                          when it is later activated.) For these
  662.                                                          kinds of events, the target (gTarget) gets
  663.                                                          the first crack at handling the event. The
  664.                                                          default implementation of the methods of
  665.                                                          TEvtHandler is to pass the event to the
  666.                                                          next element of the list. */
  667.  
  668.     TEvtHandler *fNextHandler;                            /* the next element of the list, or NIL */
  669.     long fIdleFreq;                                        /* the minimum number of ticks that can pass
  670.                                                          before my DoIdle is called. 0 = call as
  671.                                                          often as possible. n..kMaxIdleTime = call
  672.                                                          every fIdleFreq ticks. */
  673.     long fLastIdle;
  674.        /* the tick count the last time my DoIdle was
  675.                                                          called. */
  676.  
  677.                                 /* Init & Free */
  678.     virtual pascal void IEvtHandler(TEvtHandler *itsNextHandler);
  679.                 /* Sets up the reference to the next handler by setting the fNextHandler field to
  680.                 'itsNextHandler', also sets the idle frequency and resets fLastIdle field to zero.
  681.                 */
  682.  
  683.     virtual pascal void Free(void);
  684.                 /* Before calling inherited Free, changes the target to the application if the next
  685.                 handler is NIL or the next handler if there is one. */
  686.  
  687.                 /* Termination */
  688.     virtual pascal void Terminate(void);
  689.                 /* Does nothing in this class. */
  690.  
  691.                 /* Chainwalking */
  692.     virtual pascal void EachHandler(pascal void (*DoToEvtHandler)(TEvtHandler *anEvtHandler, void *
  693.        DoToEvtHandler_StaticLink), void *DoToEvtHandler_StaticLink);
  694.  
  695.         /* Performs 'DoToEvtHandler' to aFirstHandler, then to its fNextHandler, etc., onward
  696.                 until the fNextHandler chain ends at NIL */
  697.  
  698.     virtual pascal TEvtHandler *FirstHandlerThat(pascal Boolean (*TestEvtHandler)(TEvtHandler *
  699.        anEvtHandler, void *TestEvtHandler_StaticLink), void *TestEvtHandler_StaticLink);
  700.                 /* Calls TestEvtHandler for each event handler until TestEvtHandler returns true.
  701.                 Returns the TEvtHandler object for which TestEvtHandler returned true, or NIL if
  702.                 TestEvtHandler never returned true. */
  703.  
  704.     virtual pascal TEvtHandler *AddHandler(TEvtHandler *headOfChain);
  705.                 /* Adds SELF from the chain of handlers starting at headOfChain. Returns the new
  706.                 head of chain. */
  707.  
  708.     virtual pascal TEvtHandler *RemoveHandler(TEvtHandler *headOfChain);
  709.                 /* Removes SELF from the chain of handlers starting at headOfChain.  Returns the new
  710.                 head of chain (if self was the head then there _must_ be a new head. */
  711.  
  712.                 /* Debugging */
  713.     virtual pascal void IdentifySoftware(void);
  714.                 /* If fNextHandler is not NIL calls the next handler's IdentifySoftware method. */
  715.  
  716.     virtual pascal long LookupSymbol(StringPtr sym);
  717.                 /* Called by the debugger to translate a symbol into a number; default passes to the
  718.                 fNextHandler. sym will be uppercased. Return of -1 means symbol was not found. If
  719.                 sym = '?' then writeln a list of available symbols. */
  720.  
  721.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  722.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  723.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  724.                 fields. */
  725.  
  726.                 /* Events */
  727.     virtual pascal Boolean DoIdle(IdlePhase phase);
  728.                 /* Returns true if it frees itself so caller can know */
  729.  
  730.     virtual pascal Boolean DoHandleEvent(EventRecordPtr nextEvent, struct TCommand **
  731.        commandToPerform);
  732.                 /* Handle the event and return TRUE if I want it, else I don't handle it, and return
  733.                 FALSE */
  734.  
  735.                 /* Double/Triple Clicks */
  736.     virtual pascal Boolean DoMultiClick(Point lastDownPt, Point newDownPt);
  737.                 /* Called by TApplication.CountClicks. Should return TRUE if the 2 points are close
  738.                 enough to be considered part of a double/triple click. (Both points are in global
  739.                 coordinates.) This is only called if the mouse down was within the proper time
  740.                 range of the previous mouse up. Default is to pass message to the nextEventHandler
  741.                 (if one exists), otherise to require that the sum of the x & y distances is <=
  742.                 gStdHysteresis. */
  743.  
  744.                 /* Key Events */
  745.     virtual pascal struct TCommand *DoKeyCommand(short ch, short aKeyCode, EventInfo *info);
  746.                 /* Handles all keystrokes except those with the command key held down. */
  747.  
  748.     virtual pascal struct TCommand *DoCommandKey(short ch, EventInfo *info);
  749.                 /* Handles command-key combinations only. */
  750.  
  751.     virtual pascal void KeyEventToComponents(EventInfo *info);
  752.                 /* Intended to extract character components of an event in a script manager
  753.                 compatible way.  Default just forwards to next handler */
  754.  
  755.                 /* MenuEvents */
  756.     virtual pascal struct TCommand *DoMenuCommand(CmdNumber aCmdNumber);
  757.                 /* If the handler can perform the command it does so by either performing
  758.                 the command directly or by returning a TCommand. */
  759.  
  760.     virtual pascal void DoSetupMenus(void);
  761.                 /* Handles the setup of menus. */
  762.  
  763.                 /* Help */
  764.  
  765.     virtual pascal struct TCommand *DoHelp(EventInfo *info, long *message);
  766.                 /* If fNextHandler is not NIL calls its DoHelp method, otherwise returns NIL. */
  767.  
  768.                 /* View Creation from Templates*/
  769.     virtual pascal struct TView *DoCreateViews(struct TDocument *itsDocument, struct TView *
  770.        parentView, short itsRsrcID, VPoint *subViewOffset);
  771.                 /* This is the method responsible for creating view hierarchies from resource
  772.                 templates. If fNextHandler is not NIL it calls its DoCreateViews method. Otherwise
  773.                 it creates the desired view heirarchy. */
  774.  
  775.     virtual pascal struct TView *CreateAView(struct TDocument *itsDocument, struct TView *
  776.        itsSuperView, Ptr *itsParams);
  777.                 /* For creating a single view from a resource template view. If fNextHandler is not
  778.                 NIL calls its CreateAView method, otherwise it proceeds to create the desired view.
  779.                 */
  780.  
  781.                 /* Miscellaneous */
  782.     virtual pascal Boolean HandlesPrintingCommands(void);
  783.  
  784.        /* If fNextHandler is not NIL calls its same method setting this method to the result,
  785.  
  786.                 otherwise returns FALSE. */
  787.  
  788.     virtual pascal void InstallSelection(Boolean wasActive, Boolean beActive);
  789.                 /* The Target is told to do this after a window is activated or deactivated. */
  790.  
  791.     virtual pascal void SetIdleFreq(long newIdleFreq);
  792.                 /* Call to set the handler's idling frequency. */
  793.  
  794.     virtual pascal void DoChoice(struct TView *origView, short itsChoice);
  795.                 /* If its next handler is not NIL calls its DoChoice method.
  796.                 ??? should change the origView parameter to origHandler in a future version? */
  797.  
  798.                 /* Command Management */
  799.     virtual pascal void CommitLastCommand(void);
  800.                 /* Commits the last command by calling its Commit method.
  801.                 Default is to hand off to fNextHandler */
  802.  
  803.     virtual pascal struct TCommand *GetLastCommand(void);
  804.                 /* Returns the last undoable command.  The command returned is not yet committed.
  805.                 Default is to hand off to fNextHandler */
  806.  
  807.     virtual pascal struct TCommand *GetNextCommand(void);
  808.                 /* Returns a previously posted command.  Nil if there are no queued commands.
  809.                 Default is to hand off to fNextHandler */
  810.  
  811.     virtual pascal void PerformCommand(struct TCommand *command);
  812.                 /* Called to perform the given command.
  813.                 Default is to hand off to fNextHandler */
  814.  
  815.     virtual pascal void PostCommand(struct TCommand *command);
  816.                 /* Called to post a command to a queue for later execution.
  817.                 Default is to hand off to fNextHandler */
  818.  
  819. };
  820.  
  821. class TApplication : public TEvtHandler {
  822.   public:        /* The purpose of TApplication is to
  823.                                                          implement the main event loop that all
  824.                                                          Macintosh applications must have. There is
  825.                                                          only one instance of TApplication. One
  826.                                                          thing that TApplication does is to
  827.                                                          interpret the raw events that are posted
  828.                                                          and convert them into higher-level events.
  829.                                                          For example, it converts a click in the
  830.                                                          menu bar into a 'menu event' that contains
  831.                                                          the menu ID/item number that was chosen by
  832.                                                          the user. */
  833.  
  834.            /* There are not many TApplication variables--they are mostly global variables, for now…
  835.                */
  836.  
  837.     long fTicksTilNextIdle;                                /* Formerly gIdleFreq. Computed number of
  838.                                                          ticks until the next time
  839.                                                          TApplication.Idle needs to be called to
  840.                                                          dole out idle time. Also is the maximum
  841.                                                          waitTicks that we can hand off to
  842.                                                          GetEvent. */
  843.  
  844.     long fTicksOfLastIdle;                                /* Formerly gLastIdle. Time in ticks of the
  845.                                                          last time the active chain and cohandlers
  846.                                                          were idled. */
  847.  
  848.     struct TCommandList *fCommandQueue;
  849.        /* Commands that were posted for execution */
  850.     Boolean fLaunchWithNewDocument;                        /* TRUE (the default) to create a new
  851.                                                          untitled document when the application is
  852.                                                          launched without a document. */
  853.     struct TCommand *fLastCommand;                        /* the last command done or undone by the
  854.                                                          user */
  855.  
  856.                                 /* Init & Free */
  857.     virtual pascal void IApplication(OSType itsMainFileType);
  858.                 /* itsMainFileType should be the the 4-byte file type that this application
  859.                 reads/writes. We require this here so that programmers do not have to explicitly
  860.                 override TApplication.SFGetParms and supply the type there. That is the only place
  861.                 where the main file type is used. */
  862.  
  863.     virtual pascal void GetInspectorName(StringPtr inspectorName);
  864.                 /* Used to get this class's name by the Inspector. */
  865.  
  866.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  867.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  868.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  869.                 fields, in this case the global variables. */
  870.  
  871.                 /* Event Handling */
  872.     virtual pascal Boolean GetEvent(short eventMask, long sleep, RgnHandle cursorRgn, EventRecord *
  873.        anEvent);
  874.  
  875.         /* Calls WaitNextEvent (or GetNextEvent) with the given event mask, sleep, and cursor
  876.                 region parameters. You can override this if you have an alternate source for
  877.                 events. */
  878.  
  879.     virtual pascal struct TCommand *HandleAlienEvent(EventInfo *theEventInfo);
  880.                 /* This method is called upon to deal with 'application-specific' events */
  881.  
  882.     virtual pascal void MainEventLoop(void);
  883.                 /* Loop on PollEvent until the application is done */
  884.  
  885.     virtual pascal void DispatchEvent(EventInfo *theEventInfo, struct TCommand **commandToPerform);
  886.  
  887.     virtual pascal void HandleEvent(EventRecord *theEvent);
  888.                 /* When this is called by MacApp, theEvent is a pointer to the global variable
  889.                 gLastEvent. In special circumstances, you might 'fake' an event record and pass a
  890.                 pointer to it. */
  891.  
  892.     virtual pascal void PostHandleEvent(EventInfo *theEventInfo);
  893.  
  894.     virtual pascal struct TCommand *HandleActivateEvent(EventInfo *theEventInfo);
  895.                 /* Handles activate (and deactivate) events. Calls the window's Activate method, and
  896.                 sets gRedrawMenuBar to true if activating the window. Returns NIL. */
  897.  
  898.     virtual pascal struct TCommand *HandleDiskEvent(EventInfo *theEventInfo);
  899.  
  900.         /* Handles disk events. Calls DIBadMount if the high word of theEvent's message is <>
  901.                 noErr. Returns NIL. */
  902.  
  903.     virtual pascal void KeyEventToComponents(EventInfo *info);
  904.                 /* re-extracts components of an event in a script manager compatible way. */
  905.  
  906.     virtual pascal struct TCommand *HandleKeyDownEvent(EventInfo *theEventInfo);
  907.                 /* Handles key down events. If the command key is down, then this calls CommandKey.
  908.                 Otherwise it calls gTarget.DoKeyCommand. Returns the result of CommandKey or
  909.                 DoKeyCommand. */
  910.  
  911.     virtual pascal struct TCommand *HandleMouseDown(EventInfo *theEventInfo);
  912.                 /* Called when a mouse down occurs; this cases on whereMouseDown and does the right
  913.                 thing. */
  914.  
  915.     virtual pascal struct TCommand *TrackMouse(Point globalMouse, Point hysteresis, struct TCommand 
  916.        *theCommand);
  917.  
  918.                 /* Responsible for mouse tracking. */
  919.  
  920.     virtual pascal struct TCommand *HandleMouseUp(EventInfo *theEventInfo);
  921.                 /* Sets gLastUpTime. Returns NIL. */
  922.  
  923.     virtual pascal struct TCommand *HandleSystemEvent(EventInfo *theEventInfo);
  924.                 /* Handles "system" events, in particular suspend/resume events and mouse moved
  925.                 events. Calls RegainControl if switching in, AboutToLoseControl if switching out,
  926.  
  927.                 or TrackCursor if it is a mouse-moved event. Returns NIL. */
  928.  
  929.     virtual pascal struct TCommand *HandleUpdateEvent(EventInfo *theEventInfo);
  930.                 /* Handles window update events. Calls UpdateEvent for the window indicate by the
  931.                 event, and returns NIL. */
  932.  
  933.     virtual pascal Boolean IsDeskAccessory(GrafPtr aWMgrWindow);
  934.  
  935.        /* Returns true if the given Window Manager window is a desk accessory. We assume that
  936.                 if the window has a negative windowKind then it is a desk accessory. */
  937.  
  938.     virtual pascal void OpenDeskAccessory(StringPtr deskAccName);
  939.                 /* Attempts to open the desk accessory whose name is deskAccName. Called from
  940.                 TApplication.MenuEvent when an Apple menu item is chosen, and the item has a
  941.                 negative command number. */
  942.  
  943.     virtual pascal void PollEvent(Boolean allowApplicationToSleep);
  944.                 /* Polls for events calling Idle before waitNextEvent if there are no events pending
  945.                 and the application is allowed to go to sleep (kAllowApplicationToSleep),
  946.  
  947.                 calls HandleEvent with the event, if there is one. and then idles if necessary. */
  948.  
  949.     virtual pascal void Run(void);
  950.                 /* HandleFinderRequest, and if not finder printing, call MainEventLoop */
  951.  
  952.     virtual pascal void UpdateAllWindows(void);
  953.                 /* Process all update events in the queue. */
  954.  
  955.     virtual pascal Boolean InModalState(void);
  956.                 /* Returns true if the front window is modal. */
  957.  
  958.     virtual pascal Boolean InModalMenuState(void);
  959.                 /* Returns true if the front window does not allow menu commands. */
  960.  
  961.     virtual pascal void ReportEvent(EventRecord *theEvent);
  962.                 /* Displays information about an event to the debugging window. */
  963.  
  964.                 /* Target and Cohandlers */
  965.     virtual pascal void InstallCohandler(TEvtHandler *aCohandler, Boolean addIt);
  966.  
  967.        /* Used to add (addIt = TRUE) or delete (addIt = FALSE) a cohandler to/from the global
  968.                 list of cohandlers */
  969.  
  970.     virtual pascal struct TWindow *GetFrontWindow(void);
  971.                 /* Returns the window object reference for the frontmost application window (whether
  972.                 active or not. Returns nil if the FrontWindow window is not a window object */
  973.  
  974.     virtual pascal struct TWindow *GetActiveWindow(void);
  975.  
  976.        /* Returns the window object reference for the active application window.  Returns nil
  977.                 if the FrontWindow window is not a window object */
  978.  
  979.     virtual pascal void SetTarget(TEvtHandler *newTarget);
  980.                 /* Sets the current target (the head of the target chain) for the application. */
  981.  
  982.                 /* Finder Requests */
  983.     virtual pascal Boolean CanOpenDocument(CmdNumber itsCmdNumber, AppFile *anAppFile);
  984.  
  985.        /* Simulates the filtering done by Std File; this is only called when opening/printing
  986.                 documents from the finder; when using Std File, Std File does the filtering. */
  987.  
  988.     virtual pascal void HandleFinderRequest(void);
  989.  
  990.        /* Gets the info from the finder about what files to open/print and opens/prints them.
  991.                 */
  992.  
  993.                 /* Opening / Printing Documents */
  994.     virtual pascal struct TDocument *AlreadyOpen(StringPtr fileName, short volRefnum);
  995.  
  996.         /* Given a name/volRefnum, if that document is already opened, returns the TDocument.
  997.                 Otherwise returns NIL. */
  998.  
  999.     virtual pascal Boolean ChooseDocument(CmdNumber itsCmdNumber, AppFile *anAppFile);
  1000.                 /* Call this to make a Std File Get call; returns TRUE is user selected a file. */
  1001.  
  1002.     virtual pascal struct TDocument *DoMakeDocument(CmdNumber itsCmdNumber);
  1003.                 /* Must be overridden. Based on itsCmdNumber create a document object of the
  1004.                 appropriate kind. */
  1005.  
  1006.     virtual pascal CmdNumber KindOfDocument(CmdNumber itsCmdNumber, AppFilePtr itsAppFilePtr);
  1007.                 /* Given a cmd number and a specification of the file, return the cmd number to pass
  1008.                 to DoMakeDocument that indicates the type of document to make; Default is to return
  1009.                 itsCmdNumber. If you have multiple document types, a good convention is to return
  1010.                 the cmd numbers assigned to create new documents of each kind. itsAppFilePtr will be
  1011.                 NIL if we are creating a brand new document, rather than opening an existing
  1012.                 document. */
  1013.  
  1014.     virtual pascal void OpenNew(CmdNumber itsCmdNumber);
  1015.                 /* Called when the application is opened (itsCmdNumber = cFinderNew), or when NEW is
  1016.                 chosen from menu (itsCmdNumber = cNew). If you do not want to create a new document
  1017.                 when the user opens the application, override this and do nothing if itsCmdNumber =
  1018.                 cFinderNew. */
  1019.  
  1020.     virtual pascal void OpenOld(CmdNumber itsOpenCmd, AppFile *anAppFile);
  1021.                 /* Called when opening an existing document from finder (itsCmdNumber = cFinderOpen)
  1022.                 or if OPEN is chosen from menu (itsCmdNumber = cOpen). */
  1023.  
  1024.     virtual pascal Boolean PrintDocument(AppFile *anAppFile);
  1025.  
  1026.        /* Called to print a document from the finder. Returns TRUE if the user did not cancel
  1027.                 printing of the rest of the documents. */
  1028.  
  1029.     virtual pascal void SFGetParms(CmdNumber itsCmdNumber, short *dlgID, Point *where, Ptr *
  1030.        fileFilter, Ptr *dlgHook, Ptr *filterProc, TypeListHandle typeList);
  1031.                 /* Called to return all the parameters that should be passed to SFGetFile; when
  1032.                 called, typeList is a valid handle to a 0-length block. Defaults to
  1033.                 dlgID = getDlgID;
  1034.                 where = (100, 100);
  1035.                 fileFilter = NIL;
  1036.                 dlgHook = NIL;
  1037.                 filterProc = NIL;
  1038.                 typeList = list of just the main file type supported by the application. (If type
  1039.                 list ends up with nothing in it, then all file types are supported. */
  1040.  
  1041.                 /* Termination */
  1042.     virtual pascal void Close(void);
  1043.                 /* Called when the user chooses Quit from the menu, and tries to save all the open
  1044.                 documents. If all succeed the application terminates. Signals Failure with error =
  1045.                 noErr and message = msgCancelled if user cancels */
  1046.  
  1047.                 /* Hierarchy */
  1048.     virtual pascal void AddDocument(struct TDocument *aNewDocument);
  1049.                 /* Add another document to my list of documents, and make it the current one */
  1050.  
  1051.     virtual pascal void AddFreeWindow(struct TWindow *aWindow);
  1052.                 /* Add the window to the free-window list */
  1053.  
  1054.     virtual pascal void DeleteDocument(struct TDocument *docToDelete);
  1055.                 /* Delete a document from my list of documents */
  1056.  
  1057.     virtual pascal void DeleteFreeWindow(struct TWindow *windowToDelete);
  1058.                 /* Delete a window from my list of free windows */
  1059.  
  1060.     virtual pascal void EachFreeWindow(pascal void (*DoToWindow)(struct TWindow *aWindow, void *
  1061.        DoToWindow_StaticLink), void *DoToWindow_StaticLink);
  1062.                 /* Perform DoToWindow on each TWindow object in the list gFreeWindowList */
  1063.  
  1064.     virtual pascal void ForAllDocumentsDo(pascal void (*DoToDoc)(struct TDocument *aDocument, void *
  1065.        DoToDoc_StaticLink), void *DoToDoc_StaticLink);
  1066.                 /* Perform the given procedure on all open documents currently owned by the
  1067.                 application */
  1068.  
  1069.     virtual pascal void ForAllWindowsDo(pascal void (*DoToWind)(struct TWindow *aWindow, void *
  1070.        DoToWind_StaticLink), void *DoToWind_StaticLink);
  1071.                 /* Perform the given procedure on all windows known to the application, both
  1072.                 document and free windows. */
  1073.  
  1074.                 /* Window Manager Windows */
  1075.     virtual pascal void SelectWMgrWindow(GrafPtr aWMgrWindow);
  1076.  
  1077.         /* "Selects" aWMgrWindow by calling the toolbox routine SelectWindow. When any window
  1078.                 is selected, it goes through here. We never call SelectWindow directly.*/
  1079.  
  1080.     virtual pascal GrafPtr GetRsrcWindow(Ptr storage, short rsrcId, Boolean *isResizable, Boolean *
  1081.        isClosable);
  1082.  
  1083.         /* Get a Window Manger window resource whose resource id is rsrId. Return isResizable
  1084.                 and isClosable based upon the 'WIND' resource. */
  1085.  
  1086.     virtual pascal struct TWindow *WMgrToWindow(GrafPtr aWMgrWindow);
  1087.                 /* Returns the window object that represents the given Window Manager window, or NIL
  1088.                 if there is no window object. */
  1089.  
  1090.                 /* Idle Events */
  1091.     virtual pascal void Idle(IdlePhase phase);
  1092.                 /* Parcels out idle time to the DoIdle method in the target and cohandler chains of
  1093.                 TEvtHandlers. If your application needs to do something at idle time then override
  1094.                 DoIdle instead of this method. */
  1095.  
  1096.                 /* Cursor */
  1097.     virtual pascal Boolean TrackCursor(void);
  1098.                 /* Returns true if the cursor is set by a view. Otherwise the cursor is set to an
  1099.                 arrow and TrackCursor returns false.*/
  1100.  
  1101.                 /* Keyboard events */
  1102.     virtual pascal struct TCommand *DoKeyCommand(short ch, short aKeyCode, EventInfo *info);
  1103.                 /* Handle keydown events. */
  1104.  
  1105.                 /* Menu Events */
  1106.     virtual pascal struct TCommand *DoCommandKey(short ch, EventInfo *info);
  1107.                 /* Called when a keyDown event is received and the command key is down. */
  1108.  
  1109.     virtual pascal struct TCommand *MenuEvent(long menuItem);
  1110.  
  1111.        /* Given a value returned by MenuKey or MenuSelect, figure out the command number that
  1112.                 was chosen, have the application create a command object, and return it. */
  1113.  
  1114.     virtual pascal void SetUndoText(Boolean cmdDone, CmdNumber aCmdNumber);
  1115.  
  1116.         /* Called to setup the Undo menu item; if cmdDone is TRUE it reads Undo, otherwise it
  1117.                 reads Redo. aCmdNumber indicates the command that goes after the Undo/Redo. */
  1118.  
  1119.     virtual pascal void SetupTheMenus(void);
  1120.                 /* Initiates the process of enabling & checking menu items. */
  1121.  
  1122.                 /* Opening and Closing Windows */
  1123.     virtual pascal void CloseWMgrWindow(GrafPtr aWMgrWindow);
  1124.                 /* Called when user closes a window either with a menu item or with a GoAway box.
  1125.                 Signals Failure with error = noErr and message = msgCancelled if user cancels */
  1126.  
  1127.                 /* Command Management */
  1128.     virtual pascal void CommitLastCommand(void);
  1129.                 /* Commits the last command by calling its Commit method. */
  1130.  
  1131.     virtual pascal struct TCommand *GetLastCommand(void);
  1132.                 /* Returns the last undoable command.  The command returned is not yet committed.*/
  1133.  
  1134.     virtual pascal struct TCommand *GetNextCommand(void);
  1135.                 /* Returns a previously posted command.  Nil if there are no queued commands.*/
  1136.  
  1137.     virtual pascal void PerformCommand(struct TCommand *command);
  1138.  
  1139.         /* Performs the given command taking care of UNDO/REDO and clipboard related details.
  1140.                 Tracks the command first, if necessary.
  1141.                 This DOES NOT check to see if command is NIL. */
  1142.  
  1143.     virtual pascal void PostCommand(struct TCommand *command);
  1144.                 /* Called to post a command to the queue for later execution. */
  1145.  
  1146.                 /* Double/Triple Clicks */
  1147.     virtual pascal short CountClicks(EventRecordPtr aPDownEvent, short whereMouseDown);
  1148.                 /* Called by TApplication.HandleMouseDown. Returns the number of clicks that can be
  1149.                 considered multiple clicks (e.g. if it returns 1 the mouse down should be treated
  1150.                 as a single click, or possibly the first click of a multi-click sequence. If it
  1151.                 returns 2 the click should be considered a double-click, etc. A click is considered
  1152.                 part of a multi-click sequence if the mouse down was within the proper time range
  1153.                 of the previous mouse up, and was within the proper number of pixels of the last
  1154.                 mouse down. TApplication.HandleMouseDown sets theClickCount of its EventInfo record
  1155.                 to the result of this function. aPDownEvent is a pointer to the mouse down event.
  1156.                 whereMouseDown is the result of FindWindow on the event. */
  1157.  
  1158.                 /* Command Handlers */
  1159.     virtual pascal struct TCommand *DoMenuCommand(CmdNumber aCmdNumber);
  1160.                 /* Handles the application specific menu commands. */
  1161.  
  1162.     virtual pascal void DoSetupMenus(void);
  1163.  
  1164.                 /* Clipboard stuff */
  1165.  
  1166.     virtual pascal void AbandonUndoClipboard(void);
  1167.                 /* Called when the undo clipboard is no longer needed. Calls
  1168.                 gClipUndoView.FreeFromClipboard and sets gClipUndoView to NIL. */
  1169.  
  1170.     virtual pascal void AboutToLoseControl(Boolean convertClipboard);
  1171.  
  1172.         /* Called when about to activate a Desk Accessory, switch out to another application,
  1173.  
  1174.                 or Terminate. convertClipboard is generally true, except it will be FALSE if we get
  1175.                 a Swticher event that does not require Clipboard conversion */
  1176.  
  1177.     virtual pascal void AbsorbScrapStuff(void);
  1178.  
  1179.         /* Called to retrieve the current InfoScrap record from low memory. This will be used
  1180.                 to determine if the scrap has changed. */
  1181.  
  1182.     virtual pascal void CheckDeskScrap(void);
  1183.                 /* Checks to see if the desk scrap has changed by calling AbsorbScrapStuff and
  1184.                 comparing the current scrap change count with the previous change count. If the
  1185.                 scrap has changed, then the current clipboard becomes the undo clipboard and
  1186.                 ReadFromDeskScrap is called to read in the new desk scrap. */
  1187.  
  1188.     virtual pascal void ClaimClipboard(struct TView *clipView);
  1189.                 /* Makes clipView the new view displayed by the Clipboard. Typically called by a Cut
  1190.                 or Copy command. */
  1191.  
  1192.     virtual pascal long GetDataToPaste(Handle aDataHandle, ResType *dataType);
  1193.                 /* Returns the number of bytes in the paste data. Will signal Failure if it gets an
  1194.                 error. */
  1195.  
  1196.     virtual pascal void LaunchClipboard(void);
  1197.                 /* Called by TApplication.Run, before the main event loop. */
  1198.  
  1199.     virtual pascal struct TWindow *MakeClipboardWindow(void);
  1200.                 /* Called by TApplication.IApplication to make the clipboard window and associated
  1201.                 frame(s). clipView is the view to be initially installed in the clipboard--it is
  1202.                 gClipOrphanage. */
  1203.  
  1204.     virtual pascal void ReadFromDeskScrap(void);
  1205.                 /* Called at launch and when the desk scrap changes. Calls
  1206.                 TApplication.MakeViewForAlienClipboard, then ClaimClipboard */
  1207.  
  1208.     virtual pascal struct TView *MakeViewForAlienClipboard(void);
  1209.  
  1210.         /* Returns gClipOrphanage, which is capable of displaying scrap of type TEXT or PICT.
  1211.                 Override this to create a view to handle other types of scrap data. */
  1212.  
  1213.     virtual pascal void RegainControl(Boolean checkClipboard);
  1214.                 /* Called when switching in or when leaving a desk accessory */
  1215.  
  1216.     virtual pascal void SetClipView(struct TView *clipView);
  1217.                 /* Installs the given view into the clipboard window. */
  1218.  
  1219.     virtual pascal void SwapClipViews(void);
  1220.  
  1221.         /* Swaps the undo clipboard view with the current clipboard view. Used during an Undo
  1222.                 or Redo. */
  1223.  
  1224.                 /* Debugging */
  1225.     virtual pascal void IdentifySoftware(void);
  1226.  
  1227.        /* Writes out to the debug window the current version of MacApp® , UObject and UDebug.
  1228.                 */
  1229.  
  1230.                 /* Error Alerts */
  1231.  
  1232.     virtual pascal void Beep(short duration);
  1233.  
  1234.        /* Call this method when you want to beep at the user. Sound manager users may have to
  1235.                 override this method to integrate its functionality in with your application */
  1236.  
  1237.     virtual pascal void ShowError(OSErr error, long message);
  1238.                 /* Calls ErrorAlert to display an error alert. */
  1239.  
  1240.     virtual pascal void SpaceIsLow(void);
  1241.                 /* Called when space is low, at intervals of kLowSpaceInterval ticks. Displays an
  1242.                 alerting informing the user that memory space is low. Override this if you wish to
  1243.                 take more appropriate action. */
  1244.  
  1245.                 /* Miscellaneous */
  1246.  
  1247.     virtual pascal void DoShowAboutApp(void);
  1248.                 /* Called to show the "About the App" information */
  1249.  
  1250.     virtual pascal void InvalidateFocus(void);
  1251.                 /* Called to indicate that a view is unfocused when you don't know which view
  1252.                 was focused. */
  1253.  
  1254.     virtual pascal void InvalidateCursorRgn(void);
  1255.                 /* Indicates that the cursor rgn that is used to determine when MultiFinder™ should
  1256.                 wake up your application and tell you the mouse moved is invalid and must be
  1257.                 recomputed.  When not using MultiFinder™ the region is used to determine when to
  1258.                 give all the subviews a chance to set the cursor. */
  1259.  
  1260.     virtual pascal void ActivateBusyCursor(Boolean entering);
  1261.                 /* Called when the busy cursor mechanism should be activated or deactivated. */
  1262.  
  1263. };
  1264.  
  1265. /*--------------------------------------------------------------------------------------
  1266.    ------------*/
  1267. class TDocument : public TEvtHandler {
  1268.   public:        /* Corresponds to a Finder document. Manages
  1269.                                                          document data in files and in main memory.
  1270.                                                          */
  1271.     TList *fWindowList;
  1272.        /* list of windows belonging to this document
  1273.                                                          */
  1274.     TList *fViewList;                                    /* list of views belonging to document */
  1275.     struct TPrintHandler *fDocPrintHandler;                /* the object to be told to PRINT or
  1276.                                                          DoSetUpMenus when 'Print', 'Print One', or
  1277.                                                          'Page Setup…' is selected from the menu
  1278.                                                          while this is the active document. */
  1279.  
  1280.     long fChangeCount;
  1281.        /* master count of changes since last Save */
  1282.     Boolean fSavePrintInfo;                                /* if TRUE for a document saved on disk, the
  1283.                                                          'print info' record of the
  1284.                                                          fDocPrintHandler will be written out to
  1285.                                                          the data fork before other writing takes
  1286.                                                          place */
  1287.     Boolean fSharePrintInfo;
  1288.        /* if TRUE, then all printHandlers associated
  1289.                                                          with views belonging to the same document
  1290.                                                          will share the same 'print info' record */
  1291.     Handle fPrintInfo;
  1292.        /* if non-NIL, this is a handle to a 120-byte
  1293.                                                          'print info' record */
  1294.  
  1295.     StringHandle fTitle;                                /* file name */
  1296.     OSType fFileType;                                    /* file type */
  1297.     OSType fCreator;                                    /* creator ID */
  1298.     short fVolRefNum;                                    /* volume refNum */
  1299.     long fModDate;                                        /* file mod date when last read/saved */
  1300.     Boolean fReopenAlert;                                /* whether to give an alert if user reopens
  1301.                                                          doc */
  1302.     Boolean fSaveExists;                                /* whether a disk file representing this
  1303.                                                          document exists */
  1304.     Boolean fCommitOnSave;                                /* commit the last command before saving the
  1305.                                                          document, if it affected the document.
  1306.                                                          This defaults to TRUE, but carefully
  1307.                                                          written applications could set this FALSE.
  1308.                                                          */
  1309.     Boolean fUsesDataFork;
  1310.        /* whether the document uses the data fork of
  1311.                                                          the file */
  1312.     Boolean fUsesRsrcFork;
  1313.        /* whether the document uses the rsrc fork of
  1314.                                                          the file */
  1315.     Boolean fDataOpen;                                    /* whether the data fork should be open all
  1316.                                                          the time */
  1317.     Boolean fRsrcOpen;
  1318.        /* whether the resources fork be open all the
  1319.                                                          time */
  1320.     short fDataPerm;
  1321.        /* permission to use for reading data fork */
  1322.     short fRsrcPerm;                                    /* permission to use for reading the rsrc
  1323.                                                          fork */
  1324.     short fDataRefnum;                                    /* refnum; valid only if data fork is left
  1325.                                                          open */
  1326.     short fRsrcRefnum;                                    /* refnum; valid only if resource fork is
  1327.                                                          left open */
  1328.                                                        /* these will be -1 if the fork is
  1329.                                                         not open or if the corresponding
  1330.                                                         fXXXOpen flag is FALSE */
  1331.     SIPChoice fSaveInPlace;
  1332.        /* how to save files in place (if desired) */
  1333.  
  1334.                                 /* Init & Free */
  1335.     virtual pascal void IDocument(OSType itsFileType, OSType itsCreator, Boolean usesDataFork, 
  1336.        Boolean usesRsrcFork, Boolean keepsDataOpen, Boolean keepsRsrcOpen);
  1337.                 /* Initialization method for TDocument. */
  1338.  
  1339.     virtual pascal void Free(void);
  1340.  
  1341.         /* This does not call FreeData by default, since you may need to control the order in
  1342.                 which things are freed. Your override of TDocument.Free can call FreeData if
  1343.                 convenient. */
  1344.  
  1345.     virtual pascal void FreeData(void);
  1346.                 /* Called when a document is reverted, in order to free it's data objects. You may
  1347.                 also wish to call this from you document's Free method, if convenient. */
  1348.  
  1349.     virtual pascal void FreeFromClipboard(void);
  1350.                 /* Called to free a Clipboard document.Simply calls Free. */
  1351.  
  1352.     virtual pascal void GetInspectorName(StringPtr inspectorName);
  1353.                 /* Called by the Inspector to get the name of this class. */
  1354.  
  1355.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  1356.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  1357.                 /* Called by the Inspector and the Debugger to display the contents of this class's
  1358.                 fields. */
  1359.  
  1360.                 /* Opening / Printing Documents */
  1361.     virtual pascal void DoInitialState(void);
  1362.                 /* Called for 'New', 'Revert' to blank, Open Tool. Default is to do nothing; You may
  1363.                 need to do further initialization that you would not do in case of an Open… */
  1364.  
  1365.     virtual pascal void DoMakeWindows(void);
  1366.                 /* Should take the views created by DoMakeViews and create windows and frames to
  1367.                 display them. */
  1368.  
  1369.     virtual pascal void DoMakeViews(Boolean forPrinting);
  1370.  
  1371.         /* Create all necessary views for this document (based on forPrinting flag) and store
  1372.                 into fields of your document. The document will then be sent either DoMakeWindows
  1373.                 or Print. */
  1374.  
  1375.     virtual pascal void DoRead(short aRefNum, Boolean rsrcExists, Boolean forPrinting);
  1376.  
  1377.         /* rsrcExists indicates whether the document has a resource fork opened or not; it is
  1378.                 FALSE if fUsesRsrcFork is FALSE. makingCopy indicates whether this save is for
  1379.                 making a copy of the document (vs. a regular Save or Save As…); disk-based
  1380.                 documents (especially) might optimize their behavior if this is TRUE. The default
  1381.                 behaviour is to just read the printinfo from the document's data-fork (useful huh?)
  1382.                 */
  1383.  
  1384.     virtual pascal void DoWrite(short aRefNum, Boolean makingCopy);
  1385.  
  1386.         /* rsrcExists indicates whether the document has a resource fork opened or not; it is
  1387.                 FALSE if fUsesRsrcFork is FALSE. makingCopy indicates whether this save is for
  1388.                 making a copy of the document (vs. a regular Save or Save As…); disk-based
  1389.                 documents (especially) might optimize their behavior if this is TRUE. The default
  1390.                 behaviour is to just write the printinfo to the document's data-fork (useful huh?)*/
  1391.  
  1392.     virtual pascal Boolean HandlesPrintingCommands(void);
  1393.                 /* By defualt returns FALSE. */
  1394.  
  1395.     virtual pascal OSErr OpenAFile(StringPtr name, short volRefnum, Boolean openData, Boolean 
  1396.        openRsrc, short dataPerm, short rsrcPerm, short *dataRefnum, short *rsrcRefnum);
  1397.                 /* Called from ReadFromFile to open the document's data and/or resource forks.*/
  1398.  
  1399.     virtual pascal void OpenAgain(CmdNumber itsCmdNumber, TDocument *openingDoc);
  1400.                 /* Called if the user tries to open the same document twice. openingDoc will be the
  1401.                 document object being opened. Default brings SELF to the front and calls
  1402.                 Failure(noErr, 0), which will abort opening the document. (The goal is to prevent
  1403.                 the user from having 2 copies of the same document open, in which case they could
  1404.                 make incompatible changes to both.) You might override this if you want to open a
  1405.                 second window on the same document. In the ideal case, you should make both windows
  1406.                 display exactly the same data, and changes made to one should be reflected in the
  1407.                 other. You could also override this to create a read-only copy of the document. */
  1408.  
  1409.     virtual pascal void ReadFromFile(AppFile *anAppFile, Boolean forPrinting);
  1410.                 /* Called to read an existing file for display or printing. If anAppFile.fName = ''
  1411.                 THEN we read from the file specified in the instance variables instead of the
  1412.                 parameter, and the parameter will be updated to match the document. */
  1413.  
  1414.     virtual pascal void ShowWindows(void);
  1415.                 /* Called when opening the document initially; default is to call OpenWindow for all
  1416.                 windows that have fFlags.openInitially TRUE */
  1417.  
  1418.     virtual pascal void UntitledName(StringPtr noName);
  1419.                 /* Called to supply a name for an untitled document. If this returns '' then the
  1420.                 windows are not renamed from the value specified in their titles. */
  1421.  
  1422.                 /* Saving Documents */
  1423.     virtual pascal void AboutToSave(CmdNumber itsCmd, StringPtr newName, short *newVolRefnum, 
  1424.        Boolean *makingCopy);
  1425.  
  1426.        /* Called right after the SFPutFile (if any) and before deciding between SaveViaTemp &
  1427.                 SaveInPlave. Applications can use the name in an alert and/or modify the makingCopy
  1428.                 parameter if they do not want to have the document renamed. */
  1429.  
  1430.     virtual pascal void DoNeedDiskSpace(long *dataForkBytes, long *rsrcForkBytes);
  1431.  
  1432.         /* Bytes required to store SAVE file(s) on disk. When called, both parameters are set
  1433.                 to 0 for you. */
  1434.  
  1435.     virtual pascal void FreeFile(void);
  1436.                 /* Called to free in memory data associated with the currently opened document. The
  1437.                 default is to call CloseFile(fDataRefnum, fRsrcRefnum) if fDataOpen OR fRsrcOpen. */
  1438.  
  1439.     virtual pascal Boolean GetSaveInfo(CmdNumber itsCmdNumber, Boolean copyFInfo, CInfoPBRec *cInfo)
  1440.        ;
  1441.                 /* Called to get the desired file info for saving the file. Default copies the info
  1442.                 from the current file if fSaveExists AND copyFInfo, otherwise it just sets the file
  1443.                 type and creator based on the fields of SELF. If an error occurs calling the file
  1444.                 system, the cInfo record will not be filled in. Returns TRUE if it successfully
  1445.                 gets the info from the file. */
  1446.  
  1447.     virtual pascal void GetTempName(StringPtr fileName);
  1448.                 /* Return a temporary name for saving the file. The filename is constructed in two
  1449.                 parts: the first part is the document's name, or the application's name if the
  1450.                 document is untitled. The second part, appended to the first part, is a pseudo-
  1451.                 random number based on the tick count and number of seconds since boot. */
  1452.  
  1453.     virtual pascal void MakeNewCopy(Boolean makingCopy, Boolean validFInfo, CInfoPBRec *cInfo);
  1454.  
  1455.         /* Creates a brand new copy of the document in the file specified by cInfo. The name,
  1456.  
  1457.                 volume refnum, file type, and creator must be specified in cInfo. The other info
  1458.                 fields of cInfo are used only if makingCopy is FALSE. makingCopy is TRUE if this
  1459.                 save is making a copy of the document (vs. a regular Save or Save As…) Caller is
  1460.                 responsible for calling FlushVol after this. */
  1461.  
  1462.     virtual pascal short PoseSaveDialog(void);
  1463.  
  1464.        /* If the document has been changed (fChangeCount > 0), then the user is asked to save
  1465.                 the document. PoseSaveDialog returns cancel, kYesButton or kNoButton, depending on
  1466.                 the button chosen by the user. If the document has not been changed then kNoButton
  1467.                 is returned. */
  1468.  
  1469.     virtual pascal void RequestFileName(CmdNumber itsCmdNumber, Boolean makingCopy, StringPtr 
  1470.        fileName, short *volRefnum);
  1471.  
  1472.         /* Asks the user for a filename for the document. Calls TDocument.SFPutParms and then
  1473.                 SFPPutFile. Fails if the user clicks the Cancel button to end the put file dialog.
  1474.                 */
  1475.  
  1476.     virtual pascal long GetChangeCount(void);
  1477.                 /* Gets the document change count */
  1478.  
  1479.     virtual pascal void SetChangeCount(long newChangeCount);
  1480.                 /* Sets the document change count */
  1481.  
  1482.     virtual pascal void Save(CmdNumber itsCmdNumber, Boolean askForFilename, Boolean makingCopy);
  1483.                 /* Try to save the document to disk; If askForFilename, put up a Std File box; If
  1484.                 makingCopy, then this is for the Save a Copy In command, so we do not rename the
  1485.                 document. This method calls FlushVol (which takes care of the requirements of
  1486.                 MakeNewCopy, SaveInPlace, and SaveViaTemp. */
  1487.  
  1488.     virtual pascal void SaveAgain(CmdNumber itsCmdNumber, Boolean makingCopy, TDocument *savingDoc);
  1489.  
  1490.        /* Called when the user tries to Save As… or Save a Copy In… and specifies the name of
  1491.                 a document that is already opened. The default case calls Failure(errSaveAgain,
  1492.  
  1493.                 msgSaveFailed) to display an error. (The goal is to prevent the user from having 2
  1494.                 copies of the same document open, in which case they might make incompatible
  1495.                 changes to both copies.) savingDoc is the document being saved */
  1496.  
  1497.     virtual pascal void SavedOn(StringPtr fileName, short volRefnum);
  1498.                 /* Called when a save successfully completes and we are switching to the new file
  1499.                 (ie., not a Save a Copy In…). */
  1500.  
  1501.     virtual pascal void SaveInPlace(CmdNumber itsCmdNumber, Boolean makingCopy, Boolean copyFInfo, 
  1502.        StringPtr fileName, short volRefnum);
  1503.                 /* Called to save a document in place. Default is to delete the existing file if NOT
  1504.                 (fDataOpen OR fRsrcOpen). If you have disk based document, you have to decide
  1505.                 whether to allow saving in place. makingCopy is TRUE if this save is making a copy
  1506.                 of the document (vs. a regular Save or Save As…) copyFInfo is TRUE if the file
  1507.                 information should be copied to the new file Caller is responsible for calling
  1508.                 FlushVol after this. */
  1509.  
  1510.     virtual pascal void SaveViaTemp(CmdNumber itsCmdNumber, Boolean makingCopy, Boolean copyFInfo, 
  1511.        StringPtr fileName, short volRefnum);
  1512.                 /* Called to save the document by creating a temporary copy of the file and renaming
  1513.                 it. MacApp uses this method except when there is not enough disk space available.
  1514.                 makingCopy is TRUE if this save is making a copy of the document (vs. a regular
  1515.                 Save or Save As…) copyFInfo is TRUE if the file information should be copied to the
  1516.                 new file Caller is responsible for calling FlushVol after this. */
  1517.  
  1518.     virtual pascal void SFPutParms(CmdNumber itsCmdNumber, short *dlgID, Point *where, StringPtr 
  1519.        defaultName, StringPtr prompt, Ptr *dlgHook, Ptr *filterProc);
  1520.                 /* Called to return all the parameters that should be passed to
  1521.                 SFPutFile. Defaults to
  1522.                 dlgID = putDlgID;
  1523.                     where = (100, 100);
  1524.                     defaultName not changed;
  1525.                     prompt gotten from resource file;
  1526.                     dlgHook = NIL;
  1527.                     filterProc = NIL. */
  1528.  
  1529.                 /* Closing Documents */
  1530.     virtual pascal void Close(void);
  1531.                 /* Close a document and free it. Signals Failure with error = noErr and message =
  1532.                 msgCancelled if user cancels. ??? NOTE: Must never be called for a document related
  1533.                 to a view in the Clipboard. */
  1534.  
  1535.                 /* Revert */
  1536.     virtual pascal void Revert(void);
  1537.                 /* IF fSaveExists is TRUE then reverts to the file saved on disk, otherwise merely
  1538.                 resets the print handler and calls doInitialState. Calls FreeData to free any
  1539.                 existing data and commits any currently active command. */
  1540.  
  1541.     virtual pascal void Abandon(void);
  1542.  
  1543.        /* Called when a document is closed and changes are being abandoned.  For memory based
  1544.                 documents the default behaviour of doing nothing is OK.  For disk based 
  1545.    documents that
  1546.                 change the original copy this is the place to override to put back the original
  1547.                 contents if you still have it available somewhere (a scratch file?) */
  1548.  
  1549.     virtual pascal void ShowReverted(void);
  1550.                 /* Called after Revert to show brand new document; default tells each view to
  1551.                 ShowReverted */
  1552.  
  1553.                 /* Miscellaneous */
  1554.     virtual pascal void CheckDiskFile(short rsrcId, short rsrcIndex, Boolean reverting);
  1555.                 /* Check to see if the disk file has changed. If so put up alert phFileChanged after
  1556.                 setting ^0 to fTitle and ^1 to the string specified by the rsrcId and rsrcIndex. If
  1557.                 user cancels, signal Failure(noErr, msgCancelled). If reverting is TRUE,
  1558.     then I/O
  1559.                 errors and nonmatching file types will cause a Failure. Otherwise, this is a Save
  1560.                 and any I/O errors and nonmatching file type will be ignored. */
  1561.  
  1562.     virtual pascal OSErr DiskFileChanged(Boolean checkType);
  1563.                 /* Returns noErr if fSaveExists is FALSE or if the file's modification date matches
  1564.                 fModDate. If checkType is TRUE then returns errFTypeChanged if the file type has
  1565.                 changed. If the file exists but with a different modification date, returns
  1566.                 errFileChanged. */
  1567.  
  1568.     virtual pascal void SetTitle(StringPtr aTitle);
  1569.                 /* Sets SELF.fTitle to aTitle and calls SetTitleForDoc for each window of the
  1570.                 document. */
  1571.  
  1572.                 /* Command Handlers */
  1573.     virtual pascal struct TCommand *DoMenuCommand(CmdNumber aCmdNumber);
  1574.  
  1575.        /* Handles the default menu commands associated with a document and must be overridden
  1576.                 to handle any additional items. */
  1577.  
  1578.     virtual pascal void DoSetupMenus(void);
  1579.                 /* Setup the documents menus, this handles the default menus and must be overridden
  1580.                 for any additional items. */
  1581.  
  1582.                 /* Hierarchy */
  1583.     virtual pascal void AddView(struct TView *aView);
  1584.                 /* Adds the view to the end of the document's view list. */
  1585.  
  1586.     virtual pascal void AddWindow(struct TWindow *aWindow);
  1587.                 /* Adds the window to the end of the document's window list. */
  1588.  
  1589.     virtual pascal void CloseView(struct TView *aView);
  1590.                 /* Called to close a view or window associated with a document.
  1591.                 Document gets to decide whether to really close the view or not and whether to
  1592.                 close itself or not.  Does nothing if the view is not associated with the doc. */
  1593.  
  1594.     virtual pascal void DeleteView(struct TView *viewToDelete);
  1595.                 /* Deletes the view from the document's view list. */
  1596.  
  1597.     virtual pascal void DeleteWindow(struct TWindow *windowToDelete);
  1598.                 /* Deletes the window from the document's window list. */
  1599.  
  1600.     virtual pascal void ForAllViewsDo(pascal void (*DoToView)(struct TView *aView, void *
  1601.        DoToView_StaticLink), void *DoToView_StaticLink);
  1602.                 /* Performs DoToView on every view in every window belonging to the document. If you
  1603.                 want to deal with all views belonging to the document use fViewList.Each. */
  1604.  
  1605.     virtual pascal void ForAllWindowsDo(pascal void (*DoToWind)(struct TWindow *aWindow, void *
  1606.        DoToWind_StaticLink), void *DoToWind_StaticLink);
  1607.                 /* Perform the supplied proc to each window belonging to the document */
  1608.  
  1609. };
  1610.  
  1611. /*--------------------------------------------------------------------------------------
  1612.    ------------*/
  1613. typedef enum {ViewType, ViewIncludeAt} ViewTemplateSelector;  /* So C++ unions can have names */
  1614. struct viewType {
  1615.     ResType itsParentID;
  1616.     ResType thisViewID;
  1617.     VPoint itsLocation;
  1618.     VPoint itsSize;
  1619.     SizeDeterminer itsVSizeDet : 3;
  1620.     SizeDeterminer itsHSizeDet : 3;
  1621.     unsigned isShown : 1;
  1622.     unsigned isEnabled : 1;
  1623.     Byte filler;
  1624.     ResType itsSignature;
  1625.     Str255 itsType;
  1626. };
  1627.  
  1628. struct viewIncludeAt {
  1629.     ResType itsParentID;
  1630.     ResType thisViewID;
  1631.     VPoint itsLocation;
  1632.     VPoint itsSize;
  1633.     SizeDeterminer itsVSizeDet : 3;
  1634.     SizeDeterminer itsHSizeDet : 3;
  1635.     unsigned isShown : 1;
  1636.     unsigned isEnabled : 1;
  1637.     Byte filler;
  1638.     ResType itsSignature;
  1639.     short includeRsrcID;
  1640.     VPoint itsSubViewOffset;
  1641. };
  1642. union ViewTemplate {
  1643.     viewType ViewType;                                    /* Actually variable length */
  1644.     viewIncludeAt ViewIncludeAt;
  1645. };
  1646. typedef ViewTemplate *ViewTemplatePtr;
  1647.  
  1648. struct ViewResource {
  1649.     short numViews;
  1650.     ViewTemplate theViews;                                /* Actually, open-ended */
  1651. };
  1652. typedef ViewResource *ViewRsrcPtr;
  1653. typedef ViewRsrcPtr *ViewRsrcHandle;                    /* Preferred */
  1654. typedef ViewRsrcHandle ViewRsrcHndl;                    /* Left in for compatibility (2.0) */
  1655.  
  1656. /*--------------------------------------------------------------------------------------
  1657.    ------------*/
  1658.             /* Set by GetFocus; used by SetFocus. GetFocus/SetFocus are used to save and restore the
  1659.                 focus
  1660.             behind MacApp's back. One use is to speed up scrolling (see TScroller). */
  1661. #if  qExperimentalAndUnsupported
  1662. struct FocusRec {
  1663.     Boolean printing;
  1664.     Boolean drawingPictScrap;
  1665.     struct TView *drawingPictScrapView;
  1666.     struct TView *focusedView;
  1667.     VPoint longOffset;
  1668.     Point org;
  1669.     GrafPtr port;
  1670.     RgnHandle clip;
  1671.     Boolean isValid;                                /* TRUE if FocusRec is valid */
  1672. };
  1673. #endif
  1674.  
  1675. /*--------------------------------------------------------------------------------------
  1676.    ------------*/
  1677. class TView : public TEvtHandler {
  1678.   public:            /* Renders an image of a document or other
  1679.                                                          data, and identifies mouse-clicked
  1680.                                                          objects. */
  1681.     TView *fSuperView;                                    /* the current superview */
  1682.     TList *fSubViews;                                    /* subviews of this view */
  1683.     TDocument *fDocument;                                /* the associated document if any. */
  1684.     VPoint fLocation;                                    /* the location in superview coordinates */
  1685.     VPoint fSize;                                        /* the size of this view */
  1686.     SizeDeterminer fSizeDeterminer[2];
  1687.        /* how this view's size is to
  1688.                                                                          be determined */
  1689.     HLState fHLDesired;                                    /* the hilighting that is desired for this
  1690.                                                          view */
  1691.     ResType fIdentifier;                                /* the ID if any */
  1692.     Boolean fShown;                                        /* is this view to be shown */
  1693.     Boolean fViewEnabled;                                /* is this view enabled. (does it take
  1694.                                                          clicks/keystrokes */
  1695.     struct TPrintHandler *fPrintHandler;                /* the associated print handler if any. */
  1696. #if  qExperimentalAndUnsupported
  1697.     FocusRec fFocusRec;                                    /* The cached focus information */
  1698. #endif
  1699.  
  1700.                                 /* Creation/Destruction Methods */
  1701.  
  1702.     virtual pascal void IView(TDocument *itsDocument, TView *itsSuperView, VPoint *itsLocation, 
  1703.        VPoint *itsSize, SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet);
  1704.                 /* Initializes a view procedurally. */
  1705.  
  1706.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  1707.                 /* Initialize aview from a resource template. */
  1708.  
  1709.     virtual pascal void WRes(ViewRsrcHandle theResource, Ptr *itsParams);
  1710.                 /* For writing a view out to a resource. */
  1711.  
  1712.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  1713.  
  1714.         /* For writing a view to a resource works in conjunction with tbe previous method. */
  1715.  
  1716.     virtual pascal void Free(void);
  1717.                 /* Frees its subviews, then if its superview is not NIL removes itself from the
  1718.                 superviews list of subviews and if its document is not NIL removes itself from the
  1719.                 documents list of views. If it has a print handler then it frees it, then calls
  1720.                 inherited Free. */
  1721.  
  1722.     virtual pascal void FreeFromClipboard(void);
  1723.                 /* If its document is not NIL then calls the document's FreeFromClipboard method,
  1724.  
  1725.                 otherwise calls Free. */
  1726.  
  1727.                 /* Coordinate Conversion Methods */
  1728.  
  1729.     virtual pascal void QDToViewPt(Point qdPoint, VPoint *viewPt);
  1730.                 /* Convert a Quickdraw point to a view point. */
  1731.  
  1732.     virtual pascal void QDToViewRect(Rect *qdRect, VRect *viewRect);
  1733.                 /* Convert a Quickdraw rect to a view rect. */
  1734.  
  1735.     virtual pascal Point ViewToQDPt(VPoint *viewPt);
  1736.                 /* Convert a view point to a QuickDraw point. */
  1737.  
  1738.     virtual pascal void ViewToQDRect(VRect *viewRect, Rect *qdRect);
  1739.                 /* Convert a view rect to a Quickdraw rect. */
  1740.  
  1741.     virtual pascal void LocalToSuper(VPoint *thePoint);
  1742.  
  1743.         /* Given a point in local view coordinates, returns the same point in its superview's
  1744.                 coordinate system.*/
  1745.  
  1746.     virtual pascal void SuperToLocal(VPoint *thePoint);
  1747.                 /* Given a point in superview coordinates, returns the same point in the view's own
  1748.                 coordinate system. */
  1749.  
  1750.     virtual pascal void LocalToWindow(VPoint *thePoint);
  1751.  
  1752.        /* Given a point in local view coordinates, returns the same point in its window's (or
  1753.                 most super superview's) coordinate system.*/
  1754.  
  1755.     virtual pascal void WindowToLocal(VPoint *thePoint);
  1756.                 /* Given a point in window (or most super superview) coordinates, returns the same
  1757.                 point in the view's own coordinate system. */
  1758.  
  1759.                 /* SubView Management Methods */
  1760.  
  1761.     virtual pascal void EachSubView(pascal void (*DoToSubView)(TView *theSubView, void *
  1762.        DoToSubView_StaticLink), void *DoToSubView_StaticLink);
  1763.                 /* Iterate over all the views subviews passing each in turn to the procedure
  1764.                 "DoToSubView". */
  1765.  
  1766.     virtual pascal TView *FirstSubViewThat(pascal Boolean (*TestSubView)(TView *theSubView, void *
  1767.        TestSubView_StaticLink), void *TestSubView_StaticLink);
  1768.                 /* Iterate over this views subviews and return the first subview that meets
  1769.                 'TestSubView'. */
  1770.  
  1771.     virtual pascal TView *LastSubViewThat(pascal Boolean (*TestSubView)(TView *theSubView, void *
  1772.        TestSubView_StaticLink), void *TestSubView_StaticLink);
  1773.                 /* Iterate over this views subviews and return the last subview that meets
  1774.                 "TestSubView". */
  1775.  
  1776.     virtual pascal void AddSubView(TView *theSubView);
  1777.                 /* Add 'theSubView' to our list of subviews. */
  1778.  
  1779.     virtual pascal void RemoveSubView(TView *theSubView);
  1780.                 /* Remove 'theSubView' from our list of subviews. */
  1781.  
  1782.     virtual pascal void MakeFirstSubView(TView *theSubView);
  1783.                 /* Make 'theSubView ' the first subview in our list. */
  1784.  
  1785.     virtual pascal void MakeLastSubView(TView *theSubView);
  1786.                 /* Make 'theSubView' the last subview in our list. */
  1787.  
  1788.     virtual pascal short CountSubViews(void);
  1789.                 /* Return the number of subviews in our view. */
  1790.  
  1791.     virtual pascal TView *FindSubView(ResType itsIdentifier);
  1792.                 /* Find subview with identifier 'itsIdentifier' in our list of subviews. */
  1793.  
  1794.                 /* Open/Close/Activate Methods */
  1795.  
  1796.     virtual pascal void Activate(Boolean entering);
  1797.                 /* Focuses and then highlights any current selection before calling all its subviews
  1798.                 to activate themselves. */
  1799.  
  1800.     virtual pascal void Open(void);
  1801.                 /* Calls each of its subviews to Open themselves. */
  1802.  
  1803.     virtual pascal void Close(void);
  1804.  
  1805.       /* Commits the last command before calling each of its subviews to Close themselves. */
  1806.  
  1807.     virtual pascal void BeInScroller(struct TScroller *itsScroller);
  1808.                 /* If 'itsScroller' is not NIL then sets its scroll limits to  its fSize. */
  1809.  
  1810.     virtual pascal void BeInPort(GrafPtr itsPort);
  1811.                 /* If its print handler is not NIL, calls DoCheckPrinter. Then calls each of its
  1812.                 subviews to BeInPort. */
  1813.  
  1814.     virtual pascal void ShowReverted(void);
  1815.  
  1816.         /* First calls AdjustSize before forcing a redraw of the view, then call ShowReverted
  1817.                 for each of its subviews. */
  1818.  
  1819.                 /* Choice Handling Methods */
  1820.  
  1821.     virtual pascal void DoChoice(TView *origView, short itsChoice);
  1822.                 /* If its superview is not NIL calls its DoChoice method. */
  1823.  
  1824.                 /* Size Methods */
  1825.  
  1826.     virtual pascal void AdjustSize(void);
  1827.                 /* Calls ComputeSize, if the size has changed resizes itself and then calls
  1828.                 DoPagination so that any page breaks can be recalculated. */
  1829.  
  1830.     virtual pascal void CalcMinSize(VPoint *minSize);
  1831.                 /* Calculate the minimum size of SELF. */
  1832.  
  1833.     virtual pascal void ComputeSize(VPoint *newSize);
  1834.                 /* Called by MacApp®  to get the size of the view computed. */
  1835.  
  1836.     virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
  1837.                 /* Resizes SELF to 'width' & 'height', and forces an invalidation if 'invalidate' is
  1838.                 TRUE. */
  1839.  
  1840.     virtual pascal void SuperViewChangedSize(VPoint *delta, Boolean invalidate);
  1841.                 /* Called when our superview changes size. */
  1842.  
  1843.     virtual pascal void SubViewChangedSize(TView *theSubView, VPoint *delta);
  1844.                 /* Called when one of our subviews changes size. */
  1845.  
  1846.                 /* Location Methods */
  1847.  
  1848.     virtual pascal void Locate(VCoordinate h, VCoordinate v, Boolean invalidate);
  1849.                 /* Moves our view to coordinate 'h' & 'v' invalidating if 'invalidate' is TRUE. */
  1850.  
  1851.     virtual pascal void SubViewMoved(TView *theSubView);
  1852.                 /* Called when a subview is moved. */
  1853.  
  1854.     virtual pascal void SuperViewMoved(Boolean invalidate);
  1855.                 /* Called when our superview is moved. */
  1856.  
  1857.                 /* Focusing Methods */
  1858.  
  1859.     virtual pascal Boolean Focus(void);
  1860.                 /* Attempts to set up the drawing environment for this view. That consists of port,
  1861.  
  1862.                 origin, gLongOffset and clipping. Returns FALSE if not able to focus. One reason
  1863.                 focus could fail is if no superview is able to supply a port (ie not in a window
  1864.                 and not printing or drawing pict scrap). Focus will return true, however, if the
  1865.                 drawing environment can be setup but none of the view is currently visible due to
  1866.                 clipping or scrolling by a superview. This lets you assemble view hierarchies and
  1867.                 manipulate views without showing them to the user, but requires that you test
  1868.                 IsVisible if you MUST know if the view is in fact visible. (MacApp will never ask a
  1869.                 view to draw unless it is visible) */
  1870.  
  1871.     virtual pascal Boolean FocusOnSuperView(void);
  1872.                 /* Focuses on our superview. */
  1873.  
  1874.     virtual pascal void InvalidateFocus(void);
  1875.                 /* Indicates that the view's focus is no longer valid and must be recomputed. */
  1876.  
  1877.     virtual pascal Boolean IsFocused(void);
  1878.                 /* Check to see if we are currently focused. */
  1879.  
  1880.     virtual pascal void ClipFurtherTo(Rect *r, short hDeltaOrg, short vDeltaOrg);
  1881.  
  1882.        /* Set clipping to: (<current clipping> INTERSECT r) OFFSET-BY (hDeltaOrg, vDeltaOrg).
  1883.                 */
  1884.  
  1885.     virtual pascal void AssumeFocused(void);
  1886.                 /* Causes a ProgramBreak if the focused view isn't SELF */
  1887.  
  1888.                 /* Drawing Methods */
  1889.  
  1890. #if  qExperimentalAndUnsupported
  1891.     virtual pascal void DoOffScreen(pascal void (*WhatToDo)(void *WhatToDo_StaticLink), void *
  1892.        WhatToDo_StaticLink);
  1893.                 /* The WhatToDo procedure is performed while focused "offscreen" and the results
  1894.                 are blitted back on to the screen. */
  1895. #endif
  1896.  
  1897.     virtual pascal void DrawContents(void);
  1898.                 /* Causes the views contents to be drawn and that of any of its subviews. */
  1899.  
  1900.     virtual pascal void Draw(Rect *area);
  1901.                 /* Currently does nothing. Must be overridden. */
  1902.  
  1903.     virtual pascal void DoHighlightSelection(HLState fromHL, HLState toHL);
  1904.                 /* Currently does nothing. Must be overridden. */
  1905.  
  1906.     virtual pascal void Adorn(Rect *area, Point itsPenSize, unsigned short itsAdornment);
  1907.                 /* Handles the adornment of the view based on the CntlAdornment enumeration. */
  1908.  
  1909.     virtual pascal Boolean HasPendingUpdate(void);
  1910.                 /* Returns TRUE if there is a pending update event for this view, FALSE if not. */
  1911.  
  1912.     virtual pascal void Update(void);
  1913.                 /* If its window is not NIL then does an update by calling DrawContents. */
  1914.  
  1915.                 /* Validation/Invalidation Methods */
  1916.  
  1917.     virtual pascal void ForceRedraw(void);
  1918.                 /* Invalidates the entire view forcing a redraw. */
  1919.  
  1920.     virtual pascal void InvalidVRect(VRect *viewRect);
  1921.                 /* Invalidates a view rect. */
  1922.  
  1923.     virtual pascal void ValidVRect(VRect *viewRect);
  1924.             /* Converts 'viewRect' to a QD Rect then calls VisibleRect & ValidRect with the result. 
  1925.                */
  1926.  
  1927.     virtual pascal void InvalidRect(Rect *r);
  1928.                 /* Invalidates a Quickdraw rect. */
  1929.  
  1930.     virtual pascal void RevealRect(VRect *rectToReveal, Point minToSee, Boolean redraw);
  1931.  
  1932.        /* Scrolls a rect in to view, with 'minToSee' being the point which will end up at the
  1933.                 bottom of the view, i.e.the minimum amount to be seen and 'rectToReveal' the rect
  1934.                 being scrolled. */
  1935.  
  1936.     virtual pascal void RevealTop(Boolean redraw);
  1937.                 /* Scroll the top of a rect into view. */
  1938.  
  1939.     virtual pascal void RevealBottom(Boolean redraw);
  1940.                 /* Scroll the bottom of a rect into view. */
  1941.  
  1942.                 /* Mouse Handling Methods */
  1943.  
  1944.     virtual pascal Boolean ContainsMouse(VPoint *theMouse);
  1945.                 /* Is the view point 'theMouse' currently in our view. */
  1946.  
  1947.     virtual pascal Boolean HandleMouseDown(VPoint *theMouse, EventInfo *info, Point *hysteresis, 
  1948.        struct TCommand **theCommand);
  1949.  
  1950.         /* The method responsible for handling a mouse down in the view, calls DoMouseCommand
  1951.                 to handle it. */
  1952.  
  1953.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info, Point *
  1954.        hysteresis);
  1955.  
  1956.        /* Returns a simple tracker which by default calls back tracking methods of this view.
  1957.                 There are two possibilities here:
  1958.                 1)  Override DoMouseCommand to return commands that represent more complex, even
  1959.                 undoable actions.  That command may either let its tracking call back the view's
  1960.                 tracking methods (the default) which must be overridden to do anything useful or it
  1961.                 may simply do all the tracking itself.  This mostly depends on whether different
  1962.                 commands returned from the view would have different tracking behavior.  For example
  1963.                 this is the approach taken by DrawShapes.
  1964.                 2) Override the view's tracking methods and let the default tracker them
  1965.    .  For example
  1966.                 this is the approach taken by TControl. */
  1967.  
  1968.                 /* Cursor Handling Methods */
  1969.  
  1970.     virtual pascal TView *HandleCursor(VPoint *theMouse, RgnHandle cursorRgn);
  1971.                 /* Handles the setting of the cursor by calling our DoSetCursor method and the same
  1972.                 For all our subviews. */
  1973.  
  1974.     virtual pascal Boolean DoSetCursor(Point localPoint, RgnHandle cursorRgn);
  1975.  
  1976.     virtual pascal void GetDefaultCursorRgn(Point localPoint, RgnHandle cursorRgn);
  1977.                 /* Returns the largest appropriate cursor region, called by DoSetCursor. */
  1978.  
  1979.                 /* Miscellaneous Methods */
  1980.  
  1981.     virtual pascal TView *GetDialogView(void);            /* actually, TDialogView… */
  1982.                 /* If our superview is not NIL then calls its GetDialogView method and returns the
  1983.                 result, otherwise returns NIL. */
  1984.  
  1985.     virtual pascal GrafPtr GetGrafPort(void);
  1986.                 /* Returns a pointer to our Graf Port. */
  1987.  
  1988.     virtual pascal struct TScroller *GetScroller(Boolean immediateSuperView);
  1989.                 /* Returns a reference to our scroller. */
  1990.  
  1991.     virtual pascal struct TWindow *GetWindow(void);
  1992.                 /* Returns a reference to the window that we are in, if any. */
  1993.  
  1994.     virtual pascal void GetExtent(VRect *itsExtent);
  1995.                 /* Returns a view rect the size of our extent in 'itsExtent'. */
  1996.  
  1997.     virtual pascal void GetQDExtent(Rect *qdExtent);
  1998.                 /* Returns a Quickdraw rect the size of our extent in 'qdExtent'. */
  1999.  
  2000.     virtual pascal void GetFrame(VRect *itsFrame);
  2001.                 /* Returns in'itsFrame' a VRect that is the boundary of our view in superview
  2002.                 coordinates. This is calculated by adding its size to its location. */
  2003.  
  2004.     virtual pascal void GetVisibleRect(Rect *visQDRect);
  2005.                 /* Retuns a Quickdraw rect the size of the visible amount of our view. */
  2006.  
  2007.     virtual pascal void ViewEnable(Boolean state, Boolean redraw);
  2008.                 /* Enables & Redraws the view based on 'state' & 'redraw'. */
  2009.  
  2010.     virtual pascal Boolean IsViewEnabled(void);
  2011.                 /* Checks to see if our view is currently enabled. */
  2012.  
  2013.     virtual pascal void Show(Boolean state, Boolean redraw);
  2014.                 /* If 'state' is not fShown then set fShown to TRUE and call ForceRedraw if 'redraw'
  2015.                 is TRUE. Otherwise invalidate our focus and set fShown to 'state'. */
  2016.  
  2017.     virtual pascal Boolean IsShown(void);
  2018.                 /* Checks to see if our view is currently shown. */
  2019.  
  2020.     virtual pascal Boolean IsVisible(void);
  2021.                 /* Returns TRUE if any portion of the view is currently visible when focused */
  2022.  
  2023.                 /* Clipboard Handling */
  2024.  
  2025.     virtual pascal Boolean ContainsClipType(ResType aType);
  2026.                 /* Checks to see if the clipboard contains the type 'aType'. */
  2027.  
  2028.     virtual pascal long GivePasteData(Handle aDataHandle, ResType dataType);
  2029.  
  2030.      /* Gets the scrap data of the type 'dataType', returns any errors as function result. */
  2031.  
  2032.     virtual pascal void WriteToDeskScrap(void);
  2033.                 /* Writes to desk scrap. */
  2034.  
  2035.                 /* PrintingMethods */
  2036.  
  2037.     virtual pascal void AttachPrintHandler(struct TPrintHandler *itsPrintHandler);
  2038.                 /* Called by the PrintHandler during its initialization, NOT directly by you */
  2039.  
  2040.     virtual pascal VCoordinate DoBreakFollowing(VHSelect vhs, VCoordinate prevBreak, Boolean *
  2041.        automatic);
  2042.                 /* Returns the location of the page break which follows the page break located at
  2043.                 'prevBreak', in direction vhs; returns automatic = TRUE if the page-break is
  2044.                 thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note that
  2045.                 page-breaks in dimension 'v' are drawn as vertical lines, those in dimension 'h' as
  2046.                 horizontal lines */
  2047.  
  2048.     virtual pascal void DoCalcPageStrips(Point *pageStrips);
  2049.                 /* Computes the number of horizontal and vertical page strips. */
  2050.  
  2051.     virtual pascal void DoCalcViewPerPage(VPoint *viewPerPage);
  2052.                 /* Determine how much of the view normally goes into each printed page, in each
  2053.                 dimension. */
  2054.  
  2055.     virtual pascal void DoCheckPrinter(void);
  2056.  
  2057.        /* Check whether printer (if relevant) has changed, and if so, take appropriate action
  2058.                 */
  2059.  
  2060.     virtual pascal void DoDrawPrintFeedback(Rect *area);
  2061.                 /* Draw page-breaks, page-numbers, view-borders, rulers, etc. */
  2062.  
  2063.     virtual pascal void DoDrawPageBreak(VHSelect vhs, short whichBreak, VCoordinate loc, Boolean 
  2064.        automatic);
  2065.                 /* Draw one page break. */
  2066.  
  2067.     virtual pascal struct TCommand *DoMenuCommand(CmdNumber aCmdNumber);
  2068.                 /* Enables my fPrintHandler to handle commands */
  2069.  
  2070.     virtual pascal void DoPagination(void);
  2071.                 /* Recompute the dividing lines between areas of the view which will be mapped into
  2072.                 different printed pages */
  2073.  
  2074.     virtual pascal void DoPrinterChanged(void);
  2075.  
  2076.         /* The metrics relating to printer use have changed; absorb the information and react
  2077.                 */
  2078.  
  2079.     virtual pascal void DoSetPageOffset(VPoint *coord);
  2080.                 /* Only reimplement in very unusual circumstances involving Tall-UnAdjusted text
  2081.                 printing etc. */
  2082.  
  2083.     virtual pascal void DoSetupMenus(void);
  2084.                 /* Tells my PrintHandler to set up its menus */
  2085.  
  2086.     virtual pascal void GetPrintExtent(VRect *printExtent);
  2087.                 /* Returns the part of the view that is to be printed. The default is to return the
  2088.                 view's extent. */
  2089.  
  2090.     virtual pascal void PageInteriorChanged(Rect *newInterior);
  2091.                 /* Allows a view which is printable to react to the changing of the page-interior
  2092.                 rectangle */
  2093.  
  2094.                 /* Inspecting Methods */
  2095.  
  2096.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2097.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2098.                 /* Called by the Inspector and the Debugger to display the contents of this class's
  2099.                 fields. */
  2100.  
  2101.     virtual pascal void GetInspectorName(StringPtr inspectorName);
  2102.                 /* Called by the Inspector to get the name of this class. */
  2103.  
  2104.                 /* Tracking Methods */
  2105.  
  2106.     virtual pascal Boolean IsDoneTracking(void);
  2107.                 /* Indicates whether the Tracker is through tracking.  (the command is also through
  2108.                 tracking if you return NIL from TrackMouse).  Defaults to NOT StillDown.
  2109.                 Most programs won't have to mess with this.
  2110.                 NOTE you still have to deal with queued events if you change the criteri
  2111.    a for TRUE. */
  2112.  
  2113.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint, VPoint *nextPoint
  2114.        );
  2115.                 /* Override this if your Tracker calls back to the view (the Default) an you want to
  2116.                 constrain the mouse point to a grid, force drawing a square, etc. This i
  2117.    s called only
  2118.                 if fConstrainsMouse is TRUE. */
  2119.  
  2120.     virtual pascal void TrackFeedback(VPoint *anchorPoint, VPoint *nextPoint, Boolean turnItOn, 
  2121.        Boolean mouseDidMove);
  2122.                 /* Override this if your Tracker calls back to the view (the Default) an you want to
  2123.                 display any tracking feedback */
  2124.  
  2125.     virtual pascal void TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *
  2126.        previousPoint, VPoint *nextPoint, Boolean mouseDidMove);
  2127.                 /* Override this if your Tracker calls back to the view (the Default) an you want to
  2128.                 display any tracking feedback */
  2129.  
  2130. };
  2131.  
  2132. /*--------------------------------------------------------------------------------------
  2133.    ------------*/
  2134.             /* Set by GetFocus; used by SetFocus. GetFocus/SetFocus are used to save and restore the
  2135.                 focus
  2136.             behind MacApp's back. One use is to speed up scrolling (see TScroller). */
  2137. #if ! qExperimentalAndUnsupported
  2138. struct FocusRec {
  2139.     Boolean printing;
  2140.     Boolean drawingPictScrap;
  2141.     struct TView *drawingPictScrapView;
  2142.     struct TView *focusedView;
  2143.     VPoint longOffset;
  2144.     Point org;
  2145.     GrafPtr port;
  2146.     RgnHandle clip;
  2147.     Boolean isValid;                                /* TRUE if FocusRec is valid */
  2148. };
  2149. #endif
  2150.  
  2151. /*--------------------------------------------------------------------------------------
  2152.    ------------*/
  2153. struct ScrollerTemplate {
  2154.     Boolean wantVSBar;
  2155.     Boolean wantHSBar;
  2156.     long vertMax;
  2157.     long horzMax;
  2158.     short vScrollUnits;
  2159.     short hScrollUnits;
  2160.     Boolean vConstrain;
  2161.     Boolean hConstrain;
  2162.     Rect sBarOffsets;
  2163. };
  2164. typedef ScrollerTemplate *ScrollerTemplatePtr;
  2165.  
  2166. class TScroller : public TView {
  2167.   public:                /* A view which can "scroll" its contents by
  2168.                                                          translating coordinates. */
  2169.  
  2170.     VPoint fTranslation;                                /* the current amount of translation */
  2171.     VPoint fScrollLimit;                                /* the 'limit' of the subview that should be
  2172.                                                          scrollable */
  2173.     VPoint fMaxTranslation;                                /* the derived maximum amount of translation
  2174.                                                          taking into account the visible portion of
  2175.                                                          the view. This keeps us from scrolling the
  2176.                                                          bottom of a view to the top of a window */
  2177.     struct TSScrollBar *fScrollBars[2];
  2178.        /* associated scroll bars if any
  2179.                                                                       */
  2180.     Point fScrollUnit;                                    /* increment of scroll */
  2181.     Boolean fConstrain[2];                                         /* should scrolling be constrained
  2182.                                                                   to a multiple of my scrollunit */
  2183.     VRect fSBarOffsets;                                    /* how much to offset the associated scroll
  2184.                                                          bars from my bounds */
  2185.     Boolean fRespondsToFunctionKeys;                    /* if it responds to PgUp/PgDn, etc. */
  2186.  
  2187.                                      /* Creation/Destruction Methods */
  2188.  
  2189.     virtual pascal void IScroller(TView *itsSuperView, VPoint *itsLocation, VPoint *itsSize, 
  2190.        SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VCoordinate itsHorzMax, VCoordinate 
  2191.        itsVertMax, Boolean wantHorzSBar, Boolean wantVertSBar);
  2192.                 /* Called to initialize a scroller procedurally. */
  2193.  
  2194.     virtual pascal void CreateScrollBar(VHSelect itsDirection);
  2195.                 /* Called to create a scrollbar in 'itsDirection'. */
  2196.  
  2197.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2198.                 /* Initialize a scroller from a resource template. */
  2199.  
  2200.     virtual pascal void CreateTemplateScrollBar(VHSelect itsDirection);
  2201.                 /* Called to create a scrollbar in 'itsDirection' from a resource template. */
  2202.  
  2203.     virtual pascal void WRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2204.                 /* For writing a scroller view out to a resource. */
  2205.  
  2206.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2207.                 /* For writing a scroller to a resource, works in conjunction with tbe previous
  2208.                 method. */
  2209.  
  2210.     virtual pascal void Free(void);
  2211.                 /* If there are attached scrollbars frees them before calling inherited Free. */
  2212.  
  2213.                 /* SubView Management Methods */
  2214.  
  2215.     virtual pascal void AddSubView(TView *theSubView);
  2216.  
  2217.        /* Calls inherited AddSubView and then calls 'theSubView' to BeInScroller passing SELF
  2218.                 as the scroller to be in. */
  2219.  
  2220.     virtual pascal void RemoveSubView(TView *theSubView);
  2221.                 /* Calls BeInScroller with a parameter of NIL, for 'theSubView', before calling
  2222.                 inherited RemoveSubView. */
  2223.  
  2224.                 /* Focusing Methods */
  2225.  
  2226.     virtual pascal Boolean Focus(void);
  2227.                 /* Attempts to Focus the scroller by calling inherited Focus and setting the
  2228.                 gLongOffset */
  2229.  
  2230.     virtual pascal void ForceRedraw(void);
  2231.                 /* Invalidates the entire view forcing a redraw. */
  2232.  
  2233.                 /* Miscellaneous Methods */
  2234.  
  2235.     virtual pascal void LocalToSuper(VPoint *thePoint);
  2236.                 /* Given a point in local coordinates, returns the same point in its superview's
  2237.                 coordinate system. */
  2238.  
  2239.     virtual pascal void SuperToLocal(VPoint *thePoint);
  2240.                 /* Given a point in superview coordinates, returns the same point in the view's own
  2241.                 coordinate system. */
  2242.  
  2243.     virtual pascal void GetExtent(VRect *itsExtent);
  2244.                 /* Returns the extent of the scroller. */
  2245.  
  2246.                 /* Size Methods */
  2247.  
  2248.     virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
  2249.                 /* Resizes the scroller to 'width' & 'height', redrawing if 'invalidate' is TRUE. */
  2250.  
  2251.                 /* Location Methods */
  2252.  
  2253.     virtual pascal void Locate(VCoordinate h, VCoordinate v, Boolean invalidate);
  2254.                 /* Calls inherited Locate before calling AdjustScrollbars. */
  2255.  
  2256.     virtual pascal void AdjustScrollBars(Boolean invalidate);
  2257.                 /* Resizes and re-Locates the scrollbars if required. */
  2258.  
  2259.     virtual pascal void SubViewChangedSize(TView *theSubView, VPoint *delta);
  2260.                 /* Adjust the scroll limits based on the size change of the subviews. */
  2261.  
  2262.     virtual pascal void SetScrollLimits(VPoint *scrollLimit, Boolean drawScrollBars);
  2263.                 /* Sets the scroll of the attached scrollbars, if there are any. */
  2264.  
  2265.     virtual pascal void SetScrollParameters(VCoordinate horzUnits, VCoordinate vertUnits, Boolean 
  2266.        horzConstraint, Boolean vertConstraint);
  2267.                 /* Sets up the fScrollUnit and fConstrain fields of the scroller. */
  2268.  
  2269.                 /* Scrolling Methods */
  2270.  
  2271.     virtual pascal void HaveScrollBar(struct TSScrollBar *theScrollBar, VHSelect direction);
  2272.                 /* Sets the fScrollbar field in the given 'direction' to 'theScrollBar'. */
  2273.  
  2274.     virtual pascal void ScrollDraw(VPoint *delta, Boolean invalidate);
  2275.  
  2276.         /* Method responsible for actually doing the scrolling by calling moving bits. Called
  2277.                 by DoScroll.  Invalidates newly revealed area if invalidate is true else updates
  2278.                 the redraws the newly revealed area if invalidate is false.
  2279.                 !!! NOTE this does not match the behaviour of other invalidate parameter
  2280.    s because they
  2281.                 interpret invalidate equals FALSE to neither draw nor invalidate.   Well we already
  2282.                 know that the way that invalidate/redraw/don't-render control is handled
  2283.     needs _MAJOR_
  2284.                 overhauling anyways… Sigh! */
  2285.  
  2286.     virtual pascal void DoScroll(VPoint *delta, Boolean redraw);
  2287.                 /* Method responsible for handling the scrolling, calls ScrollDraw if required. */
  2288.  
  2289.     virtual pascal VCoordinate ScrollStep(VHSelect vhs, short partCode);
  2290.                 /* Depending on the 'partCode' returns the amount to be scrolled. */
  2291.  
  2292.     virtual pascal VCoordinate ScrollRelative(VHSelect vhs, VCoordinate sBarValue);
  2293.                 /* Returns the relative amount to scroll. */
  2294.  
  2295.     virtual pascal void ScrollBy(VCoordinate deltaH, VCoordinate deltaV, Boolean redraw);
  2296.                 /* Called to scroll by 'deltaH & 'deltaV'. */
  2297.  
  2298.     virtual pascal void ScrollTo(VCoordinate h, VCoordinate v, Boolean redraw);
  2299.                 /* Scroll to the required coordinates, calls ScrollBy. */
  2300.  
  2301.     virtual pascal void AutoScroll(VPoint *viewPt, VPoint *delta);
  2302.                 /* Called during auto scrolling to return the delta to be scrolled. */
  2303.  
  2304.     virtual pascal void RevealRect(VRect *rectToReveal, Point minToSee, Boolean redraw);
  2305.                 /* Shows 'rectToReveal' with the minimum amount to be seen set to 'minToSee' by
  2306.                 calling ScrollBy. */
  2307.  
  2308.                 /* Miscellaneous Methods */
  2309.  
  2310.     virtual pascal struct TCommand *DoKeyCommand(short ch, short aKeyCode, EventInfo *info);
  2311.                 /* Handles when the Home, End, PageUp & PageDown keys are used. */
  2312.  
  2313.     virtual pascal TScroller *GetScroller(Boolean immediateSuperView);
  2314.                 /* Returns SELF. */
  2315.  
  2316.                 /* Inspecting Methods */
  2317.  
  2318.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2319.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2320.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  2321.                 fields. */
  2322.  
  2323. };
  2324.  
  2325. /*--------------------------------------------------------------------------------------
  2326.    ------------*/
  2327. struct WindowTemplate {
  2328.     short procID;
  2329.     unsigned hasGoAway : 1;
  2330.     unsigned resizable : 1;
  2331.     unsigned isModal : 1;
  2332.     unsigned doFirstClick : 1;
  2333.     unsigned freeOnClosing : 1;
  2334.     unsigned disposeOnFree : 1;
  2335.     unsigned closesDocument : 1;
  2336.     unsigned openInitially : 1;
  2337.     unsigned mustAdaptToScreen : 1;
  2338.     unsigned stagger : 1;
  2339.     unsigned mustForceOnScreen : 1;
  2340.     unsigned vertCenter : 1;
  2341.     unsigned horzCenter : 1;
  2342.     unsigned filler : 3;
  2343.     ResType targetID;
  2344.     Str255 title;                                        /*Actually variable length*/
  2345. };
  2346. typedef WindowTemplate *WindowTemplatePtr;
  2347.  
  2348. class TWindow : public TView {
  2349.   public:                /* Corresponds to a desktop Window. The
  2350.                                                          outermost of a nested set of views. */
  2351.     GrafPtr fWMgrWindow;                                /* the window manager window Ptr */
  2352.     short fProcID;                                        /* the proc ID of the window */
  2353.     Rect fMoveBounds;                                    /* bounds over which the window may be moved
  2354.                                                          */
  2355.     Rect fResizeLimits;                                    /* limits over which the window may be
  2356.                                                          resized */
  2357.     TEvtHandler *fTarget;                                /* when this window is activated; the
  2358.                                                          TEvtHandler to SetTarget on */
  2359.     ResType fTargetID;                                    /* corresponding ID to fTarget */
  2360.     short fPreDocname;                                    /* amount of window title that precedes the
  2361.                                                          document name */
  2362.     short fConstTitle;                                    /* amount of the title name that is constant
  2363.                                                          */
  2364.     Boolean fIsActive;                                    /* is this window active */
  2365.     Boolean fIsResizable;                                /* is this window resizeable */
  2366.     Boolean fIsClosable;                                /* is this window closable */
  2367.     Boolean fFreeOnClosing;                                /* should this window free itself when it
  2368.                                                          closes */
  2369.     Boolean fDisposeOnFree;                                /* should the window manager window be
  2370.                                                          disposed when this window frees */
  2371.     Boolean fClosesDocument;                            /* does this window close the document */
  2372.     Boolean fOpenInitially;                                /* should this window be opened when its
  2373.                                                          document is asked to show its windows */
  2374.     Boolean fIsModal;                                    /* should this window behave modally */
  2375.     Boolean fDoFirstClick;                                /* should a click in this window not only
  2376.                                                          select it if it is inactive but also be
  2377.                                                          sent to its contents */
  2378.     Boolean fMustAdapt;                                    /* does this window require adaption to the
  2379.                                                          screen */
  2380.     Boolean fMustHorzCenter;                            /* does this window require centering
  2381.                                                          horizontally */
  2382.     Boolean fMustVertCenter;                            /* does this window require centering
  2383.                                                          vertically */
  2384.     Boolean fMustStagger;                                /* does this window require staggering */
  2385.     Boolean fMustForceOnScreen;                            /* does this window require forcing on the
  2386.                                                          screen */
  2387.     Boolean fAdapted;                                    /* has this window's size ever been adapted
  2388.                                                          to the screen */
  2389.     Boolean fHorzCentered;
  2390.        /* has this window been centered horizontally
  2391.                                                          */
  2392.     Boolean fVertCentered;
  2393.        /* has this window been centered vertically */
  2394.     Boolean fStaggered;                                    /* has this window been staggered */
  2395.     Boolean fForcedOnScreen;                            /* has this window been forced on the screen
  2396.                                                          */
  2397.     Boolean fFloats;                                    /* does this window float above non-floating
  2398.                                                          windows (NOT SUPPORTED IN 2.0) */
  2399.     Point fContRgnInset;                                /* topleft inset of cont rgn in struc rgn */
  2400.     Point fContDifference;                                /* total amount the content is less than and
  2401.                                                          offset into the structure (Accounts for
  2402.                                                          title bar, etc.) */
  2403.  
  2404.                                 /* Creation/Destruction Methods */
  2405.  
  2406.     virtual pascal void IWindow(TDocument *itsDocument, GrafPtr itsWMgrWindow, Boolean canResize, 
  2407.        Boolean canClose, Boolean disposeOnFree);
  2408.                 /* Initialize a window procedurally. */
  2409.  
  2410.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2411.                 /* Initialize a window from a resource template. */
  2412.  
  2413.     virtual pascal void WRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2414.                 /* For writing a window out to a resource. */
  2415.  
  2416.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2417.                 /* For writing a TWindow to a resource, works in conjunction with tbe previous
  2418.                 method. */
  2419.  
  2420.     virtual pascal void Free(void);
  2421.                 /* Frees the window if fDisposeOnFree is TRUE, also deletes the window from the
  2422.                 document if there is one, otherwise deletes it from the applications list of free
  2423.                 windows. */
  2424.  
  2425.                 /* Open/Close Methods */
  2426.  
  2427.     virtual pascal void Open(void);
  2428.                 /* Makes the window visible by showing it before calling inherited Open. */
  2429.  
  2430.     virtual pascal void Close(void);
  2431.                 /* Calls inherited Close and the hides & deactivates the window. */
  2432.  
  2433.     virtual pascal void CloseByUser(void);
  2434.                 /* If the window is shown and it can be closed handles the closing. */
  2435.  
  2436.     virtual pascal void GoAwayByUser(Point globalMouse);
  2437.                 /* Responsible for calling CloseByUser. */
  2438.  
  2439.                 /* Activation Methods */
  2440.  
  2441.     virtual pascal void Activate(Boolean entering);
  2442.                 /* Activate the window. */
  2443.  
  2444.                 /* Size/Location Methods */
  2445.  
  2446.     virtual pascal void Locate(VCoordinate h, VCoordinate v, Boolean invalidate);
  2447.                 /* If fWMgrWindow is not NIL then MoveWindow to relocate the window. */
  2448.  
  2449.     virtual pascal void MoveByUser(Point globalMouse);
  2450.                 /* Handles the user moving the window by dragging the title bar, calls DragWindow to
  2451.                 handle movement. */
  2452.  
  2453.     virtual pascal void ResizeByUser(Point globalMouse);
  2454.                 /* Handles the user resizing the window by dragging the growbox, calls GrowWindow to
  2455.                 handle movement and Resize to resize the window. */
  2456.  
  2457.     virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
  2458.                 /* Used to resize the window by setting its width & height to the parameters passed
  2459.                 in. */
  2460.  
  2461.     virtual pascal void Zoom(short partCode);
  2462.                 /* Responsible for actually handling the zooming of a window when the user clicks in
  2463.                 the zoombox. */
  2464.  
  2465.     virtual pascal void ZoomByUser(Point globalMouse, short partCode);
  2466.                 /* handles the user clicking in the zoombox to zoom the window, calls Zoom. */
  2467.  
  2468.                 /* Focusing Methods */
  2469.  
  2470.     virtual pascal Boolean Focus(void);
  2471.  
  2472.        /* Attempts to set the Focus to the window, returns TRUE if it succeeds, FALSE if not.
  2473.                 */
  2474.  
  2475.     virtual pascal Boolean FocusOnSuperView(void);
  2476.  
  2477.         /* Attempts to set the Focus to our superview, returning TRUE if it succeeds or FALSE
  2478.                 if not. */
  2479.  
  2480.                 /* Drawing Methods */
  2481.  
  2482.     virtual pascal void DrawContents(void);
  2483.  
  2484.       /* Does an EraseRect and calls inherited DrawContents before calling DrawResizeIcon. */
  2485.  
  2486.     virtual pascal void DrawResizeIcon(void);
  2487.                 /* Draws the grow icon by calling the toolbox routine DrawGrowIcon. */
  2488.  
  2489.                 /* Mouse Handling Methods */
  2490.  
  2491.     virtual pascal Boolean HandleMouseDown(VPoint *theMouse, EventInfo *info, Point *hysteresis, 
  2492.        struct TCommand **theCommand);
  2493.                 /* Handles mouse downs in the window. */
  2494.  
  2495.     virtual pascal Boolean HasPendingUpdate(void);
  2496.                 /* Returns TRUE if there is a pending update event for this window, FALSE if not. */
  2497.  
  2498.     virtual pascal void Update(void);
  2499.                 /* Handle the update region and drawcontents on SELF. */
  2500.  
  2501.                 /* Menu Handling Methods*/
  2502.  
  2503.     virtual pascal Boolean AllowsMenuAccess(void);
  2504.                 /* By default returns TRUE. */
  2505.  
  2506.     virtual pascal void DoSetupMenus(void);
  2507.                 /* If the window is not modal calls inherited DoSetupMenus. */
  2508.  
  2509.     virtual pascal struct TCommand *DoMenuCommand(CmdNumber aCmdNumber);
  2510.                 /* Handles closing the window. */
  2511.  
  2512.                 /* Misc. Methods */
  2513.  
  2514.     virtual pascal void Show(Boolean state, Boolean redraw);
  2515.                 /* Called to make the window visible or not based on 'state'. */
  2516.  
  2517.     virtual pascal Boolean IsShown(void);
  2518.                 /* Returns TRUE if the window is currently shown. */
  2519.  
  2520.     virtual pascal void Select(void);
  2521.                 /* Called to select the window. */
  2522.  
  2523.     virtual pascal void SetTitle(StringPtr newTitle);
  2524.                 /* Sets the windows title to 'newTitle'. */
  2525.  
  2526.     virtual pascal void GetTitle(StringPtr theTitle);
  2527.                 /* Gets the current title of the window. */
  2528.  
  2529.     virtual pascal void SetTitleForDoc(StringPtr newDocTitle);
  2530.                 /* Called when the documents name is known or changed */
  2531.  
  2532.     virtual pascal void AdaptToScreen(void);
  2533.                 /* Resizes the window to fit the screen on which it is being displayed. */
  2534.  
  2535.     virtual pascal void ForceOnScreen(void);
  2536.                 /* ForceOnScreen gaurantees that some minimal drag area is accessible to the user,
  2537.  
  2538.                   to be dragged to the desired location. */
  2539.  
  2540.     virtual pascal void Center(Boolean horizontally, Boolean vertically, Boolean forDialog);
  2541.                 /* Centers the window on the screen either horizontally, vertically or both. */
  2542.  
  2543.     virtual pascal void SimpleStagger(short dh, short dv, short *counter);
  2544.                 /* Handles the staggering of windows as they are opened. */
  2545.  
  2546.     virtual pascal GrafPtr GetGrafPort(void);
  2547.                 /* Returns the windows GrafPtr. */
  2548.  
  2549.     virtual pascal void GetGlobalBounds(Rect *globalBounds);
  2550.                 /* Returns a rectangle that is the global bounds of the window. */
  2551.  
  2552.     virtual pascal GDHandle GetMaxIntersectedDevice(Rect *screenRect);
  2553.                 /* Returns the screenRect of the most intersected device & its GDHandle, or
  2554.                   if CQD isn't available it returns GetGrayRgn intersected with screenbits.bounds
  2555.                   and NIL for the GDHandle. */
  2556.  
  2557.     virtual pascal TWindow *GetWindow(void);
  2558.                 /* Returns SELF. */
  2559.  
  2560.     virtual pascal void SetResizeLimits(Point itsMinSize, Point itsMaxSize);
  2561.                 /* Used to set the limits to which the window can be resized. */
  2562.  
  2563.     virtual pascal void SetTarget(TEvtHandler *newTarget);
  2564.                 /* Set fTarget to 'newTarget' and if we are the active window then call
  2565.                 gApplication.SetTarget. */
  2566.  
  2567.     virtual pascal void InstallDocument(TDocument *itsDocument);
  2568.                 /* Sets our fDocument field to 'itsDocument' and then installs the SELF in the
  2569.                 document, if the document is not NIL. */
  2570.  
  2571.     virtual pascal Boolean IsDraggable(Rect *whichRect);
  2572.                 /* Returns TRUE if any of the corner points of whichRect are draggable. */
  2573.  
  2574.     virtual pascal Boolean BuildWindowRgns(Boolean build);
  2575.                 /* IF build=kBuild THEN ensures that the window regions are valid; sets
  2576.                 fContRgnInset, fContDifference.
  2577.                 Cleans up if necessary, when done with window regions.
  2578.                 Returns the old state of the window regions. */
  2579.  
  2580.                 /* Inspecting Methods */
  2581.  
  2582.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2583.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2584.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  2585.                 fields. */
  2586.  
  2587.     virtual pascal void GetInspectorName(StringPtr inspectorName);
  2588.                 /* Used by the Inspector to get the name of this class. */
  2589.  
  2590. };
  2591.  
  2592. /*--------------------------------------------------------------------------------------
  2593.    ------------*/
  2594. struct ControlTemplate {
  2595.     CntlAdornment itsAdornment;
  2596.     Byte filler1;
  2597.     Point itsPenSize;
  2598.     unsigned isSizable : 1;
  2599.     unsigned isDimmed : 1;
  2600.     unsigned isHilited : 1;
  2601.     unsigned canDismiss : 1;
  2602.     unsigned filler2 : 12;
  2603.     Rect itsInset;
  2604.     Style itsTextFace;
  2605.     short itsTextSize;
  2606.     RGBColor itsTextColor;
  2607.     Str255 itsFontName;                                    /*Actually a variable length P-String*/
  2608. };
  2609. typedef ControlTemplate *ControlTemplatePtr;
  2610.  
  2611. class TControl : public TView {
  2612.   public:                /* An abstract class that represents a
  2613.                                                          control. */
  2614.     short fDefChoice;                                    /* the choice to automatically pass up the
  2615.                                                          line via DoChoice */
  2616.     Boolean fHilite;                                    /* is this view hilited */
  2617.     Boolean fDimmed;                                    /* is this view dimmed */
  2618.     Boolean fSizeable;                                    /* is the control portion of this view
  2619.                                                          sizeable */
  2620.     Boolean fDismissesDialog;                            /* can this view dismiss it's dialogview */
  2621.     CntlAdornment fAdornment;                            /* the adornment to be drawn in addition to
  2622.                                                          the view */
  2623.     Point fPenSize;                                        /* pen size to be used in adorning */
  2624.     Rect fInset;
  2625.        /* amount to inset the control portion of the
  2626.                                                          view */
  2627.     TextStyle fTextStyle;                                /* the TextStyle to use when rendering this
  2628.                                                          view */
  2629.  
  2630.     virtual pascal void IControl(TView *itsSuperView, VPoint *itsLocation, VPoint *itsSize, 
  2631.        SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet);
  2632.                 /* Initialize a control procedurally. */
  2633.  
  2634.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2635.                 /* Initialize a control from a resource template. */
  2636.  
  2637.     virtual pascal void WRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2638.                 /* For writing a control view out to a resource. */
  2639.  
  2640.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2641.                 /* For writing a control view to a resource, works in conjunction with tbe previous
  2642.                 method. */
  2643.  
  2644.     virtual pascal void ComputeSize(VPoint *newSize);
  2645.                 /* Called to compute the control's size. */
  2646.  
  2647.     virtual pascal Boolean ContainsMouse(VPoint *theMouse);
  2648.                 /* Returns TRUE if 'theMouse is currently in the controls area. */
  2649.  
  2650.     virtual pascal void ControlArea(Rect *theArea);
  2651.                 /* Returns in 'theArea' the controls active area. */
  2652.  
  2653.     virtual pascal void Dim(void);
  2654.                 /* Dims the control by drawing over it with a gray pattern. */
  2655.  
  2656.     virtual pascal void DimState(Boolean state, Boolean redraw);
  2657.                 /* If we are not currently dimmed then set fDimmed to 'state.and if 'redraw' is TRUE
  2658.                 then call DrawContents. */
  2659.  
  2660.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info, Point *
  2661.        hysteresis);
  2662.                 /* Creates a control tracker command, which is returned. */
  2663.  
  2664.     virtual pascal void Draw(Rect *area);
  2665.                 /* Calls Adorn to handle any adornments and the Dim & Hilite if required. */
  2666.  
  2667.     virtual pascal Boolean Focus(void);
  2668.                 /* Calls inherited Focus and if its TRUE then sets the port's text style and returns
  2669.                 TRUE, if it can't be focused returns FALSE. */
  2670.  
  2671.     virtual pascal void Flash(void);
  2672.                 /* Causes a control to flash with an 8 tick delay. */
  2673.  
  2674.     virtual pascal void Hilite(void);
  2675.                 /* Hilites the control by inverting its controlarea. */
  2676.  
  2677.     virtual pascal void HiliteState(Boolean state, Boolean redraw);
  2678.                 /* If our fHilite is not 'state' the set it to 'state' before calling Hilite. Note:
  2679.                 hilite is only called if 'redraw is TRUE and we can Focus. */
  2680.  
  2681.     virtual pascal void Inset(short dh, short dv, Boolean redraw);
  2682.  
  2683.         /* If we are sizable then offset fInset to 'dh' & 'dv' redrawing if 'redraw' is TRUE.
  2684.                 */
  2685.  
  2686.     virtual pascal Boolean IsDimmed(void);
  2687.                 /* Returns TRUE if the control is currently dimmed. */
  2688.  
  2689.     virtual pascal void SetInset(Rect *newInset, Boolean redraw);
  2690.                 /* Set fInset to 'newInset' redrawing if 'redraw' is TRUE. */
  2691.  
  2692.     virtual pascal void InstallColor(RGBColor *theColor, Boolean redraw);
  2693.  
  2694.         /* Sets the color field of our text style record to 'theColor', if 'redraw' then call
  2695.                 DrawContents. */
  2696.  
  2697.     virtual pascal void InstallTextStyle(TextStyle *theTextStyle, Boolean redraw);
  2698.                 /* Sets fTextStyle to 'theTextStyle', if 'redraw' then call DrawContents. */
  2699.  
  2700.     virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
  2701.                 /* Calls inherited Resize before calling ForceRedraw. */
  2702.  
  2703.     virtual pascal void TrackFeedback(VPoint *anchorPoint, VPoint *nextPoint, Boolean turnItOn, 
  2704.        Boolean mouseDidMove);
  2705.                 /* Doesn't use the default feedback */
  2706.  
  2707.     virtual pascal void TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *
  2708.        previousPoint, VPoint *nextPoint, Boolean mouseDidMove);
  2709.                 /* Called back from tracking command. Handles tracking of the mouse and then calls
  2710.                 DoChoice on TrackRelease. */
  2711.  
  2712.     virtual pascal long Validate(void);
  2713.                 /* By default returns 'noErr'. */
  2714.  
  2715.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2716.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2717.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  2718.                 fields. */
  2719.  
  2720. };
  2721.  
  2722. /*--------------------------------------------------------------------------------------
  2723.    ------------*/
  2724. class TCtlMgr : public TControl {
  2725.   public:                /* An abstract class that represents a
  2726.                                                          toolbox Control Manager control. */
  2727.     ControlHandle fCMgrControl;                            /* the Control Manager Control that is being
  2728.                                                          managed */
  2729.     short fBitsToShift;                                    /* # bits shifted to convert between short
  2730.                                                          and long value. */
  2731.     VCoordinate fLongVal;                                /* the current value */
  2732.     VCoordinate fLongMin;                                /* the minimum setting */
  2733.     VCoordinate fLongMax;                                /* the maximum setting */
  2734.  
  2735.     virtual pascal void ICtlMgr(TView *itsSuperView, VPoint *itsLocation, VPoint *itsSize, 
  2736.        SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, StringPtr itsTitle, long itsVal, long
  2737.         itsMin, long itsMax, short itsProcID);
  2738.                 /* Initialize procedurally. */
  2739.  
  2740.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2741.                 /* Initialize from a resource template. */
  2742.  
  2743.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2744.                 /* For writing a CtlMgr view to a resource. */
  2745.  
  2746.     virtual pascal void Free(void);
  2747.  
  2748.         /* Set the size of control to zero call DisposeControl, then  call inherited Free. */
  2749.  
  2750.     virtual pascal void BeInPort(GrafPtr itsPort);
  2751.                 /* Sets the control to be in 'itsPort', by setting the contrlOwner field of the
  2752.                 ControlHandle. */
  2753.  
  2754.     virtual pascal void CreateCMgrControl(Rect *itsBounds, StringPtr itsTitle, long itsVal, long 
  2755.        itsMin, long itsMax, short itsProcID);
  2756.                 /* Used to create a new control, calls NewControl to create the control. */
  2757.  
  2758.     virtual pascal void DimState(Boolean state, Boolean redraw);
  2759.                 /* Set the dim state to 'state' and redrawing it if 'redraw'. */
  2760.  
  2761.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info, Point *
  2762.        hysteresis);
  2763.                 /* Handles mouse downs in the control by calling TestControl and DoChoice, returns
  2764.                 NIL. */
  2765.  
  2766.     virtual pascal void Draw(Rect *area);
  2767.                 /* Draws the control by calling the toolbox routine ShowControl. */
  2768.  
  2769.                 /* Methods to manipulate the TCtlMgr values */
  2770.     virtual pascal VCoordinate GetLongMax(void);
  2771.                 /* Returns the current fLongMax value. */
  2772.  
  2773.     virtual pascal VCoordinate GetLongMin(void);
  2774.                 /* Returns the current fLongMin value. */
  2775.  
  2776.     virtual pascal VCoordinate GetLongVal(void);
  2777.                 /* Returns the current fLongVal value. */
  2778.  
  2779.     virtual pascal void SetLongMax(VCoordinate itsMax, Boolean redraw);
  2780.                 /* Sets fLongMax to 'itsMax', redrawing if required. */
  2781.  
  2782.     virtual pascal void SetLongMin(VCoordinate itsMin, Boolean redraw);
  2783.                 /* Sets flongMin to 'itsMin', redrawing if required. */
  2784.  
  2785.     virtual pascal void SetLongVal(VCoordinate itsVal, Boolean redraw);
  2786.                 /* Sets fLongVal to 'itsVal' redrawing if required. */
  2787.  
  2788.     virtual pascal void SetLongValues(VCoordinate itsVal, VCoordinate itsMin, VCoordinate itsMax, 
  2789.        Boolean redraw);
  2790.                 /* Sets all of the values at once, redrawing if required. */
  2791.  
  2792.                 /* Methods to manipulate the Control Manager control values */
  2793.     virtual pascal short GetMax(void);
  2794.                 /* Returns the maximum value of the Control Manager control. */
  2795.  
  2796.     virtual pascal short GetMin(void);
  2797.                 /* Returns the minimum value of the Control Manager control. */
  2798.  
  2799.     virtual pascal void GetText(StringPtr theText);
  2800.                 /* Returns the controls title, if any. */
  2801.  
  2802.     virtual pascal short GetVal(void);
  2803.                 /* Returns the current value of the Control Manager control. */
  2804.  
  2805.     virtual pascal void SetMax(short itsMax, Boolean redraw);
  2806.  
  2807.        /* While focused sets the maximum value of the Control Manager control to 'itsMax'. */
  2808.  
  2809.     virtual pascal void SetMin(short itsMin, Boolean redraw);
  2810.  
  2811.        /* While focused sets the minimum value of the Control Manager control to 'itsMin'. */
  2812.  
  2813.     virtual pascal void SetText(StringPtr itsText, Boolean redraw);
  2814.                 /* Sets the controls title to 'itsText', redrawing if required. */
  2815.  
  2816.     virtual pascal void SetVal(short newVal, Boolean redraw);
  2817.        /* While focused sets the Control Manager controls value to 'newVal', redrawing if requi
  2818.           red. */
  2819.  
  2820.     virtual pascal void SetValues(short itsVal, short itsMin, short itsMax, Boolean redraw);
  2821. /* While focused sets all the values of the Control Manager control, at once, redrawing 
  2822.    if required. */
  2823.  
  2824.     virtual pascal void HiliteState(Boolean state, Boolean redraw);
  2825.  
  2826.        /* Set the hilite state to 'state', redrawing if required.If hilite state is currently
  2827.                 'state' then does nothing. */
  2828.  
  2829.     virtual pascal Boolean IsCMgrVisible(void);
  2830.                 /* Returns TRUE if the control is currently visible, FALSE if not. */
  2831.  
  2832.     virtual pascal void Resize(VCoordinate width, VCoordinate height, Boolean invalidate);
  2833.                 /* If the control is resizable calls the toolbox routines MoveControl & SizeControl
  2834.                 before calling inherited Resize. */
  2835.  
  2836.     virtual pascal void SetCMgrVisibility(Boolean beVisible);
  2837.                 /* Sets the visibility of the control to 'isVisible'. */
  2838.  
  2839.     virtual pascal void WhileFocused(pascal void (*DoToControl)(void *DoToControl_StaticLink), void 
  2840.        *DoToControl_StaticLink, Boolean redraw);
  2841.                 /* While focused call "DoToControl", redrawing if required. */
  2842.  
  2843.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2844.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2845.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  2846.                 fields. */
  2847. };
  2848.  
  2849. /*--------------------------------------------------------------------------------------
  2850.    ------------*/
  2851. struct ScrollBarTemplate {
  2852.     long value;
  2853.     long minimum;
  2854.     long maximum;
  2855. };
  2856. typedef ScrollBarTemplate *ScrollBarTemplatePtr;
  2857.  
  2858. class TScrollBar : public TCtlMgr {
  2859.   public:            /* A subclass of TCtlMgr that maps between
  2860.                                                          longint values for our view coordinates
  2861.                                                          and the integers of a toolbox scrollbar. */
  2862.     VHSelect fDirection;
  2863.        /* is this a horizontal or vertical scrollbar
  2864.                                                          */
  2865.  
  2866.     virtual pascal void IScrollBar(TView *itsSuperView, VPoint *itsLocation, VPoint *itsSize, 
  2867.        SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsVal, 
  2868.        long itsMin, long itsMax);
  2869.                 /* Initialize a scrollbar procedurally. */
  2870.  
  2871.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2872.                 /* Initialize a scrollbar from a resource template. */
  2873.  
  2874.     virtual pascal void WRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2875.                 /* For writing a dialog view out to a resource. */
  2876.  
  2877.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2878.                 /* For writing a scrollbar to a resource, works in conjunction with tbe previous
  2879.                 method. */
  2880.  
  2881.     virtual pascal void DeltaValue(VCoordinate delta);
  2882.                 /* Does range checking on 'delta' checking it against fLongMin & fLongMax for the
  2883.                 scrollbar. */
  2884.  
  2885.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info, Point *
  2886.        hysteresis);
  2887.                 /* Handles the mouse down in the various parts of the scrollbar. */
  2888.  
  2889.     virtual pascal void TrackScrollBar(short partCode);
  2890.                 /* Tracks the scrollbar by calling DeltaValue. */
  2891.  
  2892.     virtual pascal void ActionProc(short partCode);
  2893.  
  2894.         /* Forwarded to from the global routine: ActionProcForTScrollBar which was set as the
  2895.                 ScrollBar's action proc.  Typically forwards again to TrackScrollBar after bounds
  2896.                 checking and Updates before returning to the ScrollBar. */
  2897.  
  2898.                 /* Inspecting */
  2899.  
  2900.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2901.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2902.                 /* Used by the Inspector and the Debugger to display the contents to this class's
  2903.                 fields. */
  2904. };
  2905.  
  2906. /*--------------------------------------------------------------------------------------
  2907.    ------------*/
  2908. class TSScrollBar : public TScrollBar {
  2909.   public:        /* A subclass of TScrollBar that is
  2910.                                                          associated with one or more scrollers. */
  2911.     TList *fScrollers;                                    /* the associated scrollers if any */
  2912.  
  2913.     virtual pascal void ISScrollBar(TView *itsSuperView, VPoint *itsLocation, VPoint *itsSize, 
  2914.        SizeDeterminer itsHSizeDet, SizeDeterminer itsVSizeDet, VHSelect itsDirection, long itsMax, 
  2915.        TScroller *itsScroller);
  2916.                 /* Initialize the scrollbar procedurally. */
  2917.  
  2918.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2919.                 /* Initialize the scrollbar from a resource template. */
  2920.  
  2921.     virtual pascal void WriteRes(ViewRsrcHandle theResource, Ptr *itsParams);
  2922.                 /* For writing an sscrollbar out to a resource. */
  2923.  
  2924.     virtual pascal void Free(void);
  2925.                 /* If the scrollers are not NIL then first detach the scrollbars from them before
  2926.                 freeing the scrollers, then call inherited Free. */
  2927.  
  2928.     virtual pascal void AttachScroller(TScroller *itsScroller);
  2929.  
  2930.         /* IF 'itsScroller' is not NIL then add it to our list and attach ourselves to it. */
  2931.  
  2932.     virtual pascal void BeInPort(GrafPtr itsPort);
  2933.                 /* Call inherited BeInPort and then set our visibility based on the state of the
  2934.                 window we are in. */
  2935.  
  2936.     virtual pascal void Activate(Boolean entering);
  2937.                 /* If 'entering' is TRUE then show ourselves, otherwise just call Draw to frame our
  2938.                 area. */
  2939.  
  2940.     virtual pascal struct TCommand *DoMouseCommand(Point *theMouse, EventInfo *info, Point *
  2941.        hysteresis);
  2942.                 /* Handles mouse downs in the scrollbar. */
  2943.  
  2944.     virtual pascal void Draw(Rect *area);
  2945.                 /* Draws a frame around the controls area before calling inherited Draw. */
  2946.  
  2947.     virtual pascal void TrackScrollBar(short partCode);
  2948.                 /* Called to handle tracking of the scrollbar by calling DeltaValue. */
  2949.  
  2950.                 /* Inspecting */
  2951.  
  2952.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  2953.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  2954.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  2955.                 fields. */
  2956. };
  2957.  
  2958. /*--------------------------------------------------------------------------------------
  2959.    ------------*/
  2960. class TDeskScrapView : public TView {
  2961.   public:
  2962.    /* The default view in the Clipboard, able to
  2963.                                                          display only standard text and pictures. */
  2964.     Boolean fHavePicture;                                /* are we holding a PICT */
  2965.     Boolean fHaveText;                                    /* is there any TEXT */
  2966.     short fScrapCount;                                    /* scrapCount of the scrap represented by
  2967.                                                          this view.*/
  2968.  
  2969.     Handle fDataHandle;                                    /* if non-NIL, will be either a PicHandle to
  2970.                                                          my picture or a Handle to my Text */
  2971.  
  2972.     virtual pascal void IDeskScrapView(void);
  2973.                 /* Initialize the deskscrap view procedurally. */
  2974.  
  2975.     virtual pascal void IRes(TDocument *itsDocument, TView *itsSuperView, Ptr *itsParams);
  2976.                 /* Initialize the deskscrap view from a resource template. */
  2977.  
  2978.     virtual pascal void Free(void);
  2979.                 /* Does nothing, don't ever want to free gClipOrphange. */
  2980.  
  2981.     virtual pascal void CheckScrapContents(void);
  2982.                 /* Checks the contents of the deskscrap. */
  2983.  
  2984.     virtual pascal void CalcMinSize(VPoint *minSize);
  2985.                 /* Responsible for calculating the correct size for the deskscrap view. */
  2986.  
  2987.     virtual pascal void Draw(Rect *area);
  2988.  
  2989.         /* handles the drawing of the contents of the deskscrap, which by default is either a
  2990.                 PICT or text. */
  2991.  
  2992.     virtual pascal void SuperViewChangedSize(VPoint *delta, Boolean invalidate);
  2993.                 /* If our superview changes size then call AdjustSize & ForceRedraw. */
  2994.  
  2995.     virtual pascal void WriteToDeskScrap(void);
  2996.                 /* This view represents data that is already written to the deskscrap, so this does
  2997.                 nothing. */
  2998.  
  2999.                 /* Inspecting */
  3000.     virtual pascal void GetInspectorName(StringPtr inspectorName);
  3001.                 /* Used by the Inspector to get the name of this class. */
  3002.  
  3003.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3004.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3005.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3006.                 fields. */
  3007.  
  3008. };
  3009.  
  3010. /*--------------------------------------------------------------------------------------
  3011.    ------------*/
  3012. class TPrintHandler : public TEvtHandler {
  3013.   public:
  3014.    /* Handles printing at a specified resolution
  3015.                                                          on behalf of a view. This class is really
  3016.                                                          a non-functional stub for programs that
  3017.                                                          don't use the printing building block. */
  3018.     TView *fView;                                        /* The view whose printing is handled */
  3019.     TDocument *fDocument;                                /* the document printed by this handler */
  3020.     Point fDeviceRes;                                    /* formal printer resolution, spots per inch
  3021.                                                          */
  3022.     VPoint fViewPerPage;                                /* The amount of the view that is visible on
  3023.                                                          a page */
  3024.     short fFocusedPage;                                    /* The page number currently focused */
  3025.  
  3026.                                 /* Initialization and termination */
  3027.  
  3028.     virtual pascal void IPrintHandler(TView *itsView);
  3029.                 /* Initialize the printHandler, and associate it and 'itsView' with each other */
  3030.  
  3031.     virtual pascal void GetInspectorName(StringPtr inspectorName);
  3032.                 /* Used by the inspector to get the name of this class. */
  3033.  
  3034.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3035.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3036.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3037.                 fields. */
  3038.  
  3039.     virtual pascal void FocusOnInterior(void);
  3040.                 /* Stub */
  3041.  
  3042.     virtual pascal void SetDefaultPrintInfo(void);
  3043.                 /* Stub */
  3044.  
  3045.                 /* Printing-related reformatting and computations */
  3046.  
  3047.     virtual pascal VCoordinate BreakFollowing(VHSelect vhs, VCoordinate prevBreak, Boolean *
  3048.        automatic);
  3049.                 /* Returns the location of the page break which follows the page break located at
  3050.                 'prevBreak', in direction vhs; returns automatic = TRUE if the page-break is
  3051.                 thought of as an 'automatic' rather than a 'manual' (user-specified) one. Note that
  3052.                 page-breaks in dimension 'v' are drawn as vertical lines, those in dimension 'h' as
  3053.                 horizontal lines */
  3054.  
  3055.     virtual pascal void CalcPageStrips(Point *pageStrips);
  3056.                 /* Recalculate the number of strips of pages in each dimension */
  3057.  
  3058.     virtual pascal void CalcViewPerPage(VPoint *amtPerPage);
  3059.  
  3060.       /* Computes the amount of view, in each dimension, to be allocated to a printed page */
  3061.  
  3062.     virtual pascal void CheckPrinter(void);
  3063.                 /* See if there are changed printer-configuration parameters which need to be
  3064.                 absorbed, and if so, absorb them */
  3065.  
  3066.     virtual pascal void LocatePageInterior(short pageNumber, Point *loc);
  3067.                 /* Decide where the top-left-most point of the the interior of the page should be */
  3068.  
  3069.     virtual pascal void PrinterChanged(void);
  3070.  
  3071.         /* The metrics relating to printer use have changed; absorb the information and react
  3072.                 */
  3073.  
  3074.     virtual pascal void RedoPageBreaks(void);
  3075.                 /* Recompute the dividing lines between areas of the view which will be mapped into
  3076.                 different printed pages */
  3077.  
  3078.     virtual pascal void Reset(void);
  3079.                 /* Resets the print handler to the default values */
  3080.  
  3081.                 /* Printing-related commands */
  3082.  
  3083.     virtual pascal struct TCommand *Print(CmdNumber itsCmdNumber, Boolean *proceed); /*+*/
  3084.                 /* By default sets 'proceed' to TRUE and returns NIL. */
  3085.  
  3086.     virtual pascal Boolean SetupForFinder(void);
  3087.                 /* Intended to set up the print handler for finder printing. */
  3088.  
  3089.                 /* Printing-related screen feedback */
  3090.  
  3091.     virtual pascal void DrawPrintFeedback(Rect *area);
  3092.                 /* Draw page-breaks, page-numbers, view-borders, rulers, etc. */
  3093.  
  3094.     virtual pascal void DrawPageBreak(VHSelect vhs, short whichBreak, VCoordinate loc, Boolean 
  3095.        automatic);
  3096.                 /* Does nothing. */
  3097.  
  3098.                 /* Actual printing */
  3099.  
  3100.     virtual pascal short MaxPageNumber(void);
  3101.                 /* Returns the largest page number which could be reasonably printed, given the
  3102.                 properties of the view; in cases like a SpreadSheet, this is not necessarily as
  3103.                 large as the product (row strips) x (column strips) */
  3104.  
  3105.     virtual pascal void SetPageInterior(short pageNumber);
  3106.                 /* Set up the pad-space Interior rectangle for the given page number */
  3107.  
  3108.     virtual pascal void SetPageOffset(VPoint *coord);
  3109.                 /* Given the view coordinates of the top-left-most point of the view which is being
  3110.                 mapped into the current page (in coord), this method's job is to compute the
  3111.                 correct fRelOrigin field for the current page */
  3112.  
  3113. };
  3114.  
  3115. /*--------------------------------------------------------------------------------------
  3116.    ------------*/
  3117. class TCommand : public TObject {
  3118.   public:                /* Handles a user command, including undoing
  3119.                                                          and mouse-tracking if required. Usually
  3120.                                                          created by the part of the Application
  3121.                                                          with the greatest specific knowledge about
  3122.                                                          the action to take in response to events
  3123.                                                          and passed back to be performed at several
  3124.                                                          well defined places.*/
  3125.     CmdNumber fCmdNumber;
  3126.        /* Can be a many-to-one mapping of fCmdNumber
  3127.                                                          to TCommand */
  3128.     TView *fView;                                        /* The view affected by this command, and in
  3129.                                                          which tracking takes place, if any. */
  3130.     TDocument *fChangedDocument;                        /* the document changed by this command */
  3131.     Boolean fCmdDone;                                    /* TRUE if the last "execution" message sent
  3132.                                                          to the command was DoIt or RedoIt */
  3133.     Boolean fCanUndo;                                    /* Defaults to TRUE */
  3134.     Boolean fCausesChange;                                /* Defaults to TRUE; Marks document changed
  3135.                                                          when command is done */
  3136.     Boolean fChangesClipboard;
  3137.        /* Defaults to FALSE. Set to true for command
  3138.                                                          subclasses representing CUT and/ or COPY
  3139.                                                          commands which change the Clipboard. */
  3140.     Boolean fFreeOnCompletion;                            /* TRUE to cause the command to be freed on
  3141.                                                          completion (the default). Completion is
  3142.                                                          after DoIt for non-undoable commands and
  3143.                                                          Commit for undoable commands. */
  3144.     CommandPriority fPriority;                            /* How this command should be prioritized if
  3145.                                                          it has do compete on a prioritized basis
  3146.                                                          for execution. kNormalPriority is the
  3147.                                                          Default. Most programs won't have to mess
  3148.                                                          with this. */
  3149.     Boolean fReadyToExecute;                            /* TRUE (the default) will enable this
  3150.                                                          command to be returned from any queues
  3151.                                                          that may be holding it. Most programs
  3152.                                                          won't have to mess with this. */
  3153.     Boolean fRecurring;                                    /* FALSE (the default) will enable this
  3154.                                                          command to be removed from any command
  3155.                                                          queue that holds it because it is only
  3156.                                                          executed once. */
  3157.                 /* The remaining fields are for command objects that track the mouse.
  3158.                 A future version of MacApp will have probably have Trackers as a subclas
  3159.    s of TCommand.
  3160.                 Left now for compatibility (2.0) */
  3161.     Boolean fTracksMouse;                                /* TRUE if the command should be tracked. */
  3162.     Point fInitialPt;                                    /* Where to track from (usually where the
  3163.                                                          mouse went down) in global coordinates.
  3164.                                                          MacApp sets this field in
  3165.                                                          TApplication.HandleMooseDown, you set it
  3166.                                                          if you create trackers that don't get
  3167.                                                          passed back up through that call chain. */
  3168.  
  3169.     Boolean fConstrainsMouse;
  3170.        /* Defaults to FALSE; if you set to TRUE then
  3171.                                                          TrackConstrain will be called to constrain
  3172.                                                          the mouse. */
  3173.     Boolean fViewConstrain;                                /* Defaults to TRUE, which means constrain
  3174.                                                          mouse to view limits */
  3175.     Boolean fTrackNonMovement;
  3176.        /* Defaults to FALSE, which means don't track
  3177.                                                          mouse unless it moves. */
  3178.     TScroller *fScroller;
  3179.        /* The scroller that handles auto-scrolling */
  3180.  
  3181.                                 /* Init & Free */
  3182.     virtual pascal void ICommand(CmdNumber itsCmdNumber, TDocument *itsDocument, TView *itsView, 
  3183.        TScroller *itsScroller);
  3184.                 /* Initialize a command procedurally. */
  3185.  
  3186.                 /* Inspecting */
  3187.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3188.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3189.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3190.                 fields. */
  3191.  
  3192.                 /* command processing - usually overridden */
  3193.  
  3194.     virtual pascal void Commit(void);
  3195.                 /* Stub */
  3196.  
  3197.     virtual pascal void DoIt(void);
  3198.                 /* Stub */
  3199.  
  3200.     virtual pascal void RedoIt(void);
  3201.                 /* Stub */
  3202.  
  3203.     virtual pascal void UndoIt(void);
  3204.                 /* Stub */
  3205.  
  3206.                 /* Scheduling */
  3207.     virtual pascal Boolean IsReadyToExecute(void);
  3208.  
  3209.         /* Returns TRUE (the Default) when the command is ready to execute.  Override to base
  3210.                 the execution of the command on more sophisticated criteria.
  3211.                 Most programs won't have to mess with this.. */
  3212.  
  3213.                 /* Mouse Tracking */
  3214.  
  3215.     virtual pascal Boolean IsDoneTracking(void);
  3216.                 /* Indicates whether the Command is through tracking.  (the command is also through
  3217.                 tracking if you return NIL from TrackMouse).  Defaults to fView.IsDoneTracking.
  3218.                 Most programs won't have to mess with this.
  3219.                 NOTE you still have to deal with queued events if you change the criteri
  3220.    a for TRUE. */
  3221.  
  3222.     virtual pascal void TrackConstrain(VPoint *anchorPoint, VPoint *previousPoint, VPoint *nextPoint
  3223.        );
  3224.                 /* Override this if you want to constrain the mouse point to a grid, force drawing a
  3225.                 square, etc. This is called only if fConstrainsMouse is TRUE. */
  3226.  
  3227.     virtual pascal void TrackFeedback(VPoint *anchorPoint, VPoint *nextPoint, Boolean turnItOn, 
  3228.        Boolean mouseDidMove);
  3229.                 /* Default is: IF NOT mouseDidMove THEN FrameRect(<rect formed by anchorPoint and
  3230.                 nextPoint>). Before this is called the pen is set to PenNormal and the PenMode to
  3231.                 PatXOR. */
  3232.  
  3233.     virtual pascal TCommand *TrackMouse(TrackPhase aTrackPhase, VPoint *anchorPoint, VPoint *
  3234.        previousPoint, VPoint *nextPoint, Boolean mouseDidMove);
  3235.                 /* This does the mouse tracking. The default returns SELF. Override it to force
  3236.                 gridding, to return a different type of command, or to perform the command on mouse
  3237.                 release instead of using the usual DoIt approach. All points are in local
  3238.                 coordinates. If aTrackPhase = trackPress then all 3 points will be the same. If
  3239.                 aTrackPhase = trackRelease then nextPoint will be the coordinate in the mouseUp
  3240.                 event (if a mouseUp event is found), otherwise the same point as previousPoint.
  3241.                 Generally, you will ignore nextPoint and just look at previousPoint. mouseDidMove
  3242.                 will be TRUE if aTrackPhase = trackPress or trackRelease; otherwise, it will
  3243.                 indicate if nextPoint = previousPoint. If you change anchorPoint, the new value
  3244.                 will be passed to you next time. The value of nextPoint at the time the routine
  3245.                 exits will be passed to you as previousPoint the next time the routine is called.
  3246.                 You can change nextPoint if you wish. Usually, however, you will do gridding in the
  3247.                 TrackConstrain method. */
  3248.  
  3249.     virtual pascal void AutoScroll(VCoordinate deltaH, VCoordinate deltaV);
  3250.                 /* Implements autoscrolling by calling fScroller.ScrollBy. */
  3251.  
  3252. };
  3253.  
  3254. /*--------------------------------------------------------------------------------------
  3255.    ------------*/
  3256. class TNoChangesCommand : public TCommand {
  3257.   public:    /* Doesn't "change" the document and is not
  3258.                                                          itself undoable. Thus it doesn't flush the
  3259.                                                          last command that did. Useful for
  3260.                                                          deferring actions out to the
  3261.                                                          PerformCommand bottleneck where the stack
  3262.                                                          is unwound and the heap is unloaded for
  3263.                                                          maximum elbow room. */
  3264.     virtual pascal void INoChangesCommand(CmdNumber itsCmdNumber, TDocument *itsDocument, TView *
  3265.        itsView, TScroller *itsScroller);
  3266.  
  3267.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3268.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3269.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3270.                 fields. */
  3271.  
  3272. };
  3273.  
  3274. /*--------------------------------------------------------------------------------------
  3275.    ------------*/
  3276. class TControlTracker : public TNoChangesCommand {
  3277.   public: /* a command adapted for tracking
  3278.                                                               controls. */
  3279.     TControl *fControl;                                    /* the object of our desire */
  3280.  
  3281.     virtual pascal void IControlTracker(TControl *theControl);
  3282.                 /* Initialize the tracker procedurally. */
  3283.  
  3284.                 /* Inspecting */
  3285.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3286.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3287.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3288.                 fields. */
  3289.  
  3290. };
  3291.  
  3292. /*--------------------------------------------------------------------------------------
  3293.    ------------*/
  3294.             /* commands that are created in response to common operations and will forward to the
  3295.             appropriate action */
  3296.  
  3297. #if  qDebug
  3298. class TDebugCommand : public TNoChangesCommand {
  3299.   public:     /* Causes the MacApp Debugger to be
  3300.                                                               entered */
  3301.     virtual pascal void IDebugCommand(CmdNumber itsCmdNumber);
  3302.                 /* Initialize the DebugCommand procedurally. */
  3303.  
  3304.     virtual pascal void DoIt(void);
  3305.                 /* Cause the MacApp Debugger to be entered */
  3306.  
  3307.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3308.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3309.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3310.                 fields. */
  3311.  
  3312. };
  3313. #endif
  3314.  
  3315. /*--------------------------------------------------------------------------------------
  3316.    ------------*/
  3317. #if  qInspector
  3318. class TInspectorCommand : public TNoChangesCommand {
  3319.   public: /* Tells the inspector to make a new
  3320.                                                               window */
  3321.     virtual pascal void IInspectorCommand(CmdNumber itsCmdNumber);
  3322.                 /* Initialize the DebugCommand procedurally. */
  3323.  
  3324.     virtual pascal void DoIt(void);
  3325.                 /* Tell the inspector to make a new window */
  3326.  
  3327.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3328.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3329.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3330.                 fields. */
  3331.  
  3332. };
  3333. #endif
  3334.  
  3335. /*--------------------------------------------------------------------------------------
  3336.    ------------*/
  3337. class TNewDocCommand : public TNoChangesCommand {
  3338.   public:     /* Tells the application open a new
  3339.                                                               document. */
  3340.     virtual pascal void INewDocCommand(CmdNumber itsCmdNumber);
  3341.                 /* Initialize the NewDocCommand procedurally. */
  3342.  
  3343.     virtual pascal void DoIt(void);
  3344.                 /* tell the application open a new document. */
  3345.  
  3346.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3347.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3348.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3349.                 fields. */
  3350.  
  3351. };
  3352.  
  3353. /*--------------------------------------------------------------------------------------
  3354.    ------------*/
  3355. class TOldDocCommand : public TNoChangesCommand {
  3356.   public:     /* Tells the application to open an old
  3357.                                                               document. */
  3358.     virtual pascal void IOldDocCommand(CmdNumber itsCmdNumber);
  3359.                 /* Initialize the OldDocCommand procedurally. */
  3360.  
  3361.     virtual pascal void DoIt(void);
  3362.                 /* tell the application to open an old document. */
  3363.  
  3364.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3365.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3366.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3367.                 fields. */
  3368.  
  3369. };
  3370.  
  3371. /*--------------------------------------------------------------------------------------
  3372.    ------------*/
  3373. class TCloseWindowCommand : public TNoChangesCommand {
  3374.   public:
  3375.    /* Tells the application close a window.
  3376.                                                               */
  3377.     virtual pascal void ICloseWindowCommand(CmdNumber itsCmdNumber, TWindow *itsWindow);
  3378.                 /* Initialize the CloseWindowCommand procedurally. */
  3379.  
  3380.     virtual pascal void DoIt(void);
  3381.                 /* tell the application to close a window. */
  3382.  
  3383.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3384.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3385.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3386.                 fields. */
  3387.  
  3388. };
  3389.  
  3390. /*--------------------------------------------------------------------------------------
  3391.    ------------*/
  3392. class TQuitCommand : public TNoChangesCommand {
  3393.   public:     /* Tells the application to quit. */
  3394.     virtual pascal void IQuitCommand(CmdNumber itsCmdNumber);
  3395.                 /* Initialize the QuitCommand procedurally. */
  3396.  
  3397.     virtual pascal void DoIt(void);
  3398.                 /* tell the application to quit. */
  3399.  
  3400.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3401.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3402.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3403.                 fields. */
  3404.  
  3405. };
  3406.  
  3407. /*--------------------------------------------------------------------------------------
  3408.    ------------*/
  3409. class TUndoRedoCommand : public TNoChangesCommand {
  3410.   public: /* Tells the application to undo/redo
  3411.                                                               the last undoable command */
  3412.     virtual pascal void IUndoRedoCommand(CmdNumber itsCmdNumber);
  3413.                 /* Initialize the UndoRedoCommand procedurally. */
  3414.  
  3415.     virtual pascal void DoIt(void);
  3416.                 /* tell the application to undo/redo. */
  3417.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3418.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3419.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3420.                 fields. */
  3421.  
  3422. };
  3423.  
  3424. /*--------------------------------------------------------------------------------------
  3425.    ------------*/
  3426. class TAboutAppCommand : public TNoChangesCommand {
  3427.   public: /* Tells the application to show its
  3428.                                                               about box. */
  3429.     virtual pascal void IAboutAppCommand(CmdNumber itsCmdNumber);
  3430.                 /* Initialize the AboutAppCommand procedurally. */
  3431.  
  3432.     virtual pascal void DoIt(void);
  3433.                 /* tell the application to DoShowAboutApp. */
  3434.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3435.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3436.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3437.                 fields. */
  3438.  
  3439. };
  3440.  
  3441. /*--------------------------------------------------------------------------------------
  3442.    ------------*/
  3443. class TSaveDocCommand : public TNoChangesCommand {
  3444.   public: /* Tells the document to save. */
  3445.     virtual pascal void ISaveDocCommand(CmdNumber itsCmdNumber, TDocument *itsDocument);
  3446.                 /* Initialize the SaveDocCommand procedurally. */
  3447.  
  3448.     virtual pascal void DoIt(void);
  3449.                 /* tell the document to save. */
  3450.  
  3451.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3452.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3453.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3454.                 fields. */
  3455.  
  3456. };
  3457.  
  3458. /*--------------------------------------------------------------------------------------
  3459.    ------------*/
  3460. class TRevertDocCommand : public TNoChangesCommand {
  3461.   public: /* Tells the document to revert after
  3462.                                                               checking with the user */
  3463.     virtual pascal void IRevertDocCommand(CmdNumber itsCmdNumber, TDocument *itsDocument);
  3464.                 /* Initialize the RevertDocCommand procedurally. */
  3465.  
  3466.     virtual pascal void DoIt(void);
  3467.                 /* tell the document to revert if the user says OK. */
  3468.  
  3469.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3470.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3471.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3472.                 fields. */
  3473.  
  3474. };
  3475.  
  3476. /*--------------------------------------------------------------------------------------
  3477.    ------------*/
  3478. class TCommandList : public TSortedList {
  3479.   public:        /* A list for keeping TCommands ordered by
  3480.                                                          priority */
  3481.     virtual pascal void ICommandList(void);
  3482.                 /* Initialize the CommandList procedurally. */
  3483.  
  3484.     virtual pascal short Compare(TObject *item1, TObject *item2);
  3485.                 /* Compares Two TCommands based on their priority */
  3486.  
  3487.     virtual pascal void Insert(TObject *item);
  3488.                 /* Overridden to guarantee insertion even in low memory and to preserve arrival
  3489.                 sequence within "Compare" ordering. */
  3490.  
  3491.     virtual pascal void Fields(pascal void (*DoToField)(StringPtr fieldName, Ptr fieldAddr, short 
  3492.        fieldType, void *DoToField_StaticLink), void *DoToField_StaticLink);
  3493.                 /* Used by the Inspector and the Debugger to display the contents of this class's
  3494.                 fields. */
  3495.  
  3496. };
  3497.  
  3498. /*--------------------------------------------------------------------------------------
  3499.    ------------*/
  3500.  
  3501. extern pascal Boolean gAlwaysTrackCursor;                /* set this to TRUE when you want the
  3502.                                                          application to track the cursor even if it
  3503.                                                          doesn't stray outside gCursorRgn. */
  3504. extern pascal Boolean gAppDone;                            /* set this to TRUE when you want the
  3505.                                                          application to terminate */
  3506. extern pascal TextStyle gApplicationStyle;                /* Application's default text style */
  3507.             /*$Push*/ /*$J+*/
  3508. extern "C" TApplication *gApplication;                /* the application object */
  3509.             /*$Pop*/
  3510.  
  3511. #if  qDebug
  3512. extern pascal Boolean gAssumeFocused;                    /* Actually do TView.AssumeFocused checking?
  3513.                                                          */
  3514. extern pascal Boolean gBusyTempRgn;                        /* Is gTempRgn in use? */
  3515. #endif
  3516. extern pascal Boolean gChooserOK;                        /* if FALSE, user will not be allowed to
  3517.                                                          change the printer selection using 'Choose
  3518.                                                          Printer' DA while the application is
  3519.                                                          alive; if TRUE (the default set in
  3520.                                                          InitUMacApp), then printer-change will
  3521.                                                          only be disabled during background
  3522.                                                          printing. If you want it FALSE in your
  3523.                                                          application, the right time to set it is
  3524.                                                          after calling InitUMacApp (where it is
  3525.                                                          initialized to TRUE) and before calling
  3526.                                                          InitPrinting (where, if it's found to be
  3527.                                                          FALSE, the low- memory location governing
  3528.                                                          is option is poked). In the MultiFinder™
  3529.                                                          world this is pretty questionable
  3530.                                                          behaviour, though. */
  3531. extern pascal short gClickCount;
  3532.    /* number of 'saved up' mouse clicks; handled
  3533.                                                          in TApplication.DispatchEvent, ObeyEvent &
  3534.                                                          ObeyMouseDown. If a mouseDown, the value
  3535.                                                          is that returned by the call to
  3536.                                                          TApplication.CountClicks. If a mouseUp,
  3537.  
  3538.                                                          the value is left alone. Otherwise, set to
  3539.                                                          0. Also set to 0 is the 2 clicks were in
  3540.                                                          different parts ofthe window. */
  3541. extern pascal Boolean gClipClaimed;
  3542.    /* Used by PerformCommand & ClaimClipboard to
  3543.                                                          determine, if DoIt of a cut/copy cmd
  3544.                                                          fails, whether the Clipboard had already
  3545.                                                          been claimed by the new command or not */
  3546. extern pascal TView *gClipOrphanage;
  3547.    /* A view to represent the Clipboard when the
  3548.                                                          application can't */
  3549.  
  3550. extern pascal TView *gClipUndoView;                        /* The view previously installed in the
  3551.                                                          Clipboard */
  3552.  
  3553. extern pascal TView *gClipView;                            /* The view currently installed in the
  3554.                                                          Clipboard */
  3555. extern pascal TWindow *gClipWindow;
  3556.    /* The window holding the Clipboard display */
  3557. extern pascal Boolean gClipWrittenToDeskScrap;            /* True if the clipboard view has been
  3558.                                                          written to the desk scrap. */
  3559. extern pascal Boolean gCouldPrint;                        /* whether Printer code is accessible to the
  3560.                                                          application */
  3561. extern pascal TPrintHandler *gCurrPrintHandler;            /* If printing, this is set to the print
  3562.                                                          handler. Nil if not printing. */
  3563. #if  qDebug
  3564. extern pascal Boolean gDebugPrinting;                    /* simple toggle for debugging printing */
  3565. #endif
  3566. extern pascal TList *gDocList;                            /* list of documents */
  3567. extern pascal Boolean gDrawingPictScrap;                /* TRUE if a view's Draw routine is being
  3568.                                                          called in order to create PICT data in the
  3569.                                                          Desk Scrap; your View.Draw can check this
  3570.                                                          routine, and insert PictComments as
  3571.                                                          appropriate if it wishes to have them in
  3572.                                                          the Picture in the Desk Scrap */
  3573. extern pascal TView *gDrawingPictScrapView;
  3574.    /* the view being currently drawn in the PICT
  3575.                                                          scrap ??? this stuff is a good candidate
  3576.                                                          for a small change to the view
  3577.                                                          architecture to more easily allow
  3578.                                                          providing alternate drawing environments */
  3579. #if  qExperimentalAndUnsupported
  3580. extern pascal Boolean gEnableDoubleBuffering;            /* TRUE to enable automatic double buffering
  3581.                                                         when drawing/scrolling views */
  3582. #endif
  3583. extern pascal Str255 gErrorParm3;                        /* This is used as the last argument to
  3584.                                                          ParamText in ErrorAlert, if ErrorAlert
  3585.                                                          displays one of the standard alerts. (This
  3586.                                                          string will replace ^3 in those alerts.)
  3587.                                                          ErrorAlert also sets this to '' when
  3588.                                                          called. You can use this to parameterize
  3589.                                                          the automatic alerts that MacApp displays.
  3590.                                                          For example, TDocument.ReadFromFile sets
  3591.                                                          this to the document name. */
  3592. extern pascal short gEventLevel;                        /* A count of the number of nested calls to
  3593.                                                          PollEvent. */
  3594. #if  qDebug
  3595. extern pascal Boolean gExperimenting;                    /* simple toggle for enabling/disabling
  3596.                                                          experimental features */
  3597. #endif
  3598. extern pascal WindowRecord gFakeWindow;                    /* In MacApp 2.0 and earlier, this was
  3599.                                                          initialized with OpenPort, or OpenCPort,
  3600.                                                          and by setting its ControlList to NIL.
  3601.                                                          This was NOT a real window, just a port.
  3602.                                                          In MacApp 2.0.1 and later, this is a
  3603.                                                          real window. It's ignored in routines that
  3604.                                                          iterate over the windowList. */
  3605.  
  3606. extern pascal short gFileCount;                            /* # files to open/print from finder; set in
  3607.                                                          Init2 */
  3608. extern pascal Boolean gFinderPrinting;
  3609.    /* TRUE if the Finder started the App up just
  3610.                                                          for printing docs */
  3611. extern pascal TView *gFocusedView;                        /* the view that is currently focused */
  3612. extern pascal TList *gFreeWindowList;                    /* list of free-standing (documentless)
  3613.                                                          windows */
  3614. extern pascal Boolean gGotClipType;                        /* True if we can paste the data in the
  3615.                                                          clipboard */
  3616. extern pascal TEvtHandler *gHeadCohandler;                /* head of linked list of global co-handlers
  3617.                                                          */
  3618. extern pascal IdlePhase gIdlePhase;                        /* The current idle phase */
  3619. extern pascal Boolean gInBackground;                    /* True if app is currently in background */
  3620. extern pascal Boolean gInitialized;                        /* Set to TRUE at the end of IApplication */
  3621. #if  qDebug
  3622. extern pascal Boolean gIntenseDebugging;
  3623.    /* debugging toggle for intensive debugging */
  3624. #endif
  3625. extern pascal short gLastClickPart;                        /* the list window part clicked in-used for
  3626.                                                          double click detection */
  3627. extern pascal long gLastDeskAcc;
  3628.    /* time of the most recent possible excursion
  3629.                                                          to a a Desk Accessory */
  3630. extern pascal Point gLastMsePt;                            /* coordinates of mouse in last event passed
  3631.                                                          to TApplication.CountClicks */
  3632. extern pascal long gLastUpTime;                            /* time of last mouse up event passed to
  3633.                                                          TApplication.ObeyEvent */
  3634. extern pascal VPoint gLongOffset;                        /* Used in focusing */
  3635. extern pascal long gLowSpaceInterval;                    /* If >= 0, the frequency (in Ticks) with
  3636.                                                          which MacApp displays a low space alert.
  3637.                                                          (Defaults to kLowSpaceInterval.) If < 0,
  3638.  
  3639.                                                          MacApp doesn't display an alert. */
  3640. extern pascal Ptr gMacAppAlertFilter;                    /* the default filter proc. Will be
  3641.                                                          automatically set to point to
  3642.                                                          MacAppAlertFilter. Set this to nil in your
  3643.                                                          code if you don't want it or call it from
  3644.                                                          your own filter proc if you just want to
  3645.                                                          add behavior. Someday we will fix all this
  3646.                                                          to be Object based. */
  3647. extern pascal Boolean gInFilter;                        /* Flag that is set when we are in the
  3648.                                                          MacAppAlertFilter, used to indicate if we
  3649.                                                          should re-enter MacApp to handle updates
  3650.                                                          or not */
  3651. extern pascal Boolean gInhibitNestedHandling;            /* TRUE if Failure was executed and the
  3652.                                                          outer- most event loop has not been
  3653.                                                          reached or the ErrorAlert routing has not
  3654.                                                          yet shown the failure to the user. Also
  3655.                                                          may be set to TRUE to inhibit continued
  3656.                                                          operation of MacApp Activate/Update
  3657.                                                          handling and idling during MacAppAlerts. */
  3658. extern pascal short gMainEventMask;                        /* Event mask used in main event loop.
  3659.                                                          Initialized by InitUMacApp. */
  3660. extern pascal OSType gMainFileType;                        /* principal file type opened/printed by
  3661.                                                          application; set in
  3662.                                                          TApplication.IApplication; by default,
  3663.  
  3664.                                                          TApplication.SFGetFilters returns a list
  3665.                                                          of just this */
  3666. extern pascal short gMBarDisplayed;                        /* menus that are read in and installed in
  3667.                                                          menu bar */
  3668. extern pascal short gMBarHierarchical;                    /* menus that pop up when a menu item is
  3669.                                                          choosen */
  3670. extern pascal short gMBarNotDisplayed;
  3671.    /* menus that are read in but not installed */
  3672. extern pascal ScrapStuff gNewScrapStuff;                /* the current ScrapStuff record used in
  3673.                                                          tracking the scrap */
  3674. extern pascal long gNextSpaceMsg;
  3675.    /* time when next low space message should be
  3676.                                                          displayed */
  3677. extern pascal TPrintHandler *gNullPrintHandler;            /* handles printing-relating messages for
  3678.                                                          views which don't print */
  3679. extern pascal short gNumUntitled;                        /* The number to assign to the next Untitled
  3680.                                                          document (assuming that the app provides a
  3681.                                                          template for filling in the number. You
  3682.                                                          must change STR# resource with ID 0 /
  3683.                                                          index 3 to read (for example)
  3684.                                                          Untitled-<<<#>>>. */
  3685. extern pascal TCommand *gNoChanges;                        /* Value to return when the handler doesn't
  3686.                                                          return a command. You can just use NIL
  3687.                                                          now. (Left in for compatibility (2.0) */
  3688. extern pascal Boolean gOldChooserFlag;                    /* The state of the chooser alert flag when
  3689.                                                          the application started up. */
  3690. extern pascal ScrapStuff gOldScrapStuff;                /* the last ScrapStuff record used in
  3691.                                                          tracking the scrap */
  3692. extern pascal VHSelect gOrthogonal[2];                          /* An Orthogonal set of VHSelects.
  3693.                                                                gOrthogonal[v] = h and
  3694.                                                                gOrthogonal[h] = v */
  3695. extern pascal VPoint gPageOffset;                        /* offset in view of page being printed */
  3696. extern pascal ResType gPrefClipType;
  3697. extern pascal TPrintHandler *gPrintHandler;                /* a global print-handler object for use in
  3698.                                                          some standard printing-related activities;
  3699.                                                          this is initialized to be just a reference
  3700.                                                          to gNullPrintHandler, but if you call
  3701.                                                          InitPrinting, that will install a
  3702.                                                          non-trivial print-handler here… */
  3703. extern pascal Boolean gPrinting;                        /* true if currently Printing */
  3704. #if  qDebug
  3705. extern pascal Boolean gReportEvt;                        /* debugging toggle for reporting events */
  3706. extern pascal Boolean gReportMenuChoices;                /* debugging toggle for tracing cmds */
  3707. extern pascal short gRsrcCheck;                            /* debugging toggle for checking resource
  3708.                                                          usage */
  3709. #endif
  3710. extern pascal FocusRec gSaveFocusRec;                    /* a place to save off the focus to speed up
  3711.                                                          scrolling*/
  3712.  
  3713. extern pascal ResType gSignatures[32];
  3714.    /* Standard object signatures */
  3715. extern pascal ObjClassID gSignatureIds[32];                                 /* corresponding standard
  3716.                                                                           object ClassIds */
  3717. extern pascal short gSignatureCount;                    /* count of standard signatures stored */
  3718.  
  3719. extern pascal Point gStdHysteresis;                        /* standard hysteresis used in
  3720.                                                          TCommand.ICommand */
  3721. extern pascal short gStdStaggerCount;                    /* Used to stagger windows created from
  3722.                                                          templates */
  3723. extern pascal Rect gStdWMoveBounds;                        /* standard boundsRect to pass to DragWindow
  3724.                                                          Toolbox routine */
  3725. extern pascal Rect gStdWSizeRect;                        /* standard sizeRect to pass to GrowWindow
  3726.                                                          Toolbox routine */
  3727. extern pascal Rect gStdWScreenRect;
  3728.    /* Used to force a window onto the screen. If
  3729.                                                          the window is not in the GrayRgn, then at
  3730.                                                          least one corner of the window must lie
  3731.                                                          within gStdWScreenRect. */
  3732.  
  3733. extern pascal Boolean gSysWindowActive;                    /* TRUE if the front window is a system
  3734.                                                          window */
  3735. extern pascal TextStyle gSystemStyle;                    /* System's default text style */
  3736. extern pascal TEvtHandler *gTarget;
  3737.    /* the TEvtHandler that gets the first chance
  3738.                                                          at DoCommand, DoSetupMenu, DoKeyCommand,
  3739.  
  3740.                                                          Idle; should never be NIL -- If you do not
  3741.                                                          want your own target set this to the
  3742.                                                          application object */
  3743.  
  3744. extern pascal RgnHandle gTempRgn;                        /* gTempRgn is a temporary RgnHandle created
  3745.                                                          in InitUMacApp. When debugging: before
  3746.                                                          using gTempRgn, call UseTempRgn and when
  3747.                                                          done call DoneWithTempRgn; this ensures
  3748.                                                          that 2 routines do not try to use gTempRgn
  3749.                                                          and the same time */
  3750. #if  qDebug
  3751. extern pascal Boolean gTraceIdle;                        /* allow tracing through idle */
  3752. #endif
  3753. extern pascal Boolean gUndoState;                        /* are we in undo or redo */
  3754. extern pascal CmdNumber gUndoCmd;                        /**/
  3755. #if  qDebug
  3756. extern pascal Str255 gUsedBy;                            /* The routine using gTempRgn */
  3757. #endif
  3758. extern pascal Boolean gVarClipPicSize;                    /* if TRUE, Pictures in the Clipboard are
  3759.                                                          treated as variable size, depending on the
  3760.                                                          window size; if FALSE (default), then
  3761.                                                          pictures in the Clipboard are drawn and
  3762.                                                          pasted ??? actual size */
  3763. #if  qDebug
  3764. extern pascal Boolean gWasTrcEnable;                    /* Used to store old tracing state across
  3765.                                                          idleBegin/idleEnd calls to Idle */
  3766. #endif
  3767. extern pascal ResType gWResSignature;                    /* Signature used by TView.WRes */
  3768. extern pascal Str255 gWResType;                            /* Type used by TView.WRes */
  3769. extern pascal GrafPtr gWorkPort;                        /* Pointer to a graf port that is created
  3770.                                                          during initialization */
  3771.  
  3772.             /* Pascal doesn't have structured constants so… */
  3773. extern pascal Rect gZeroRect;                            /* SetRect(gZeroRect, 0, 0, 0, 0); */
  3774. extern pascal Point gZeroPt;                            /* SetPt(gZeroPt, 0, 0); */
  3775. extern pascal VPoint gZeroVPt;                            /* SetVPt(gZeroVPt, 0, 0); */
  3776. extern pascal VRect gZeroVRect;                            /* SetVRect(gZeroVRect, 0, 0, 0, 0); */
  3777.  
  3778.             /* These are really private but, they're here in case access is needed. */
  3779. extern pascal StringHandle pCopyright;
  3780. extern pascal TrapPatch pETSPatch;                        /* patch for ExitToShell */
  3781. extern pascal FailInfo pFi;                                /* Outermost failure handler */
  3782.  
  3783. /*--------------------------------------------------------------------------------------
  3784.    ------------*/
  3785.  
  3786.             /* D E B U G G I N G */
  3787.  
  3788. #if  qDebug
  3789.  
  3790. extern pascal void DoneWithTempRgn(void);
  3791.         /* Indicates that gTempRgn is no longer in use. Call this only if qDebug is true. */
  3792.  
  3793. extern pascal void EntDebugger(Boolean entering);
  3794.         /* Call to enter the MacApp Debugger */
  3795.  
  3796. extern pascal void UseTempRgn(StringPtr byWhom);
  3797.         /* Call this when you are about to use gTempRgn and qDebug is true. Used with DoneWithTe
  3798.            mpRgn
  3799.         will prevent you from trying to use gTempRgn from two places at the same time. */
  3800. #endif
  3801.  
  3802. extern pascal long LookupSymbol(StringPtr sym);
  3803.         /* Call to see if anyone knows a reference for the given symbol */
  3804.  
  3805. extern pascal void NotYetImplemented(StringPtr where);
  3806.         /* Signals the notYetImplemented failure which when caught puts up an alert saying
  3807.         "Not Yet Implemented" and in debug WriteLns where. */
  3808.  
  3809.         /* W I N D O W S */
  3810.  
  3811. extern pascal GrafPtr FreeIfWMgrWindow(GrafPtr w, Boolean dispose);
  3812.         /* Calls DisposeWindow if dispose is true, else calls CloseWindow. Does nothing if w
  3813.         is nil.
  3814.         Returns NIL for convenient assignment back to the reference passed in. */ /* Preferred */
  3815.  
  3816.  
  3817. extern pascal void FreeWMgrWindow(GrafPtr w, Boolean dispose);
  3818.         /* Left in for compatibility (2.0) */
  3819.  
  3820. extern pascal short GetWindowVariant(GrafPtr    theWindow);
  3821.  
  3822. extern pascal TWindow *NewPaletteWindow(short itsRsrcID, Boolean wantHScrollBar, Boolean 
  3823.    wantVScrollBar, TDocument *itsDocument, TView *itsMainView, TView *itsPaletteView, short 
  3824.    sizePalette, VHSelect whichWay);
  3825.         /* Utility for creating MacDraw-like windows with 1 non-scrolling palette along the left
  3826.             edge
  3827.         (whichWay = h), or a non-scrolling status area at the top of the window (whichWay = v), and
  3828.         a main view that may or may not scroll. Signals Failure if the window could not be created.
  3829.         */
  3830.  
  3831. extern pascal TWindow *NewSimpleWindow(short itsRsrcID, Boolean wantHScrollBar, Boolean 
  3832.    wantVScrollBar, TDocument *itsDocument, TView *itsView);
  3833.         /* Utility for creating simple windows that contain 1 view and may or may not scroll. Si
  3834.            gnals
  3835.         Failure if the window could not be created. */
  3836.  
  3837. extern pascal TWindow *NewTWindow(short itsRsrcID, TDocument *itsDocument);
  3838.         /* Utility for creating a window object. Used within NewPaletteWindow & NewSimpleWindow.
  3839.         SIgnals Failure if the window could not be created. */
  3840.  
  3841. extern pascal TWindow *NewTemplateWindow(short viewRsrcID, TDocument *itsDocument);
  3842.         /* Creates a window using a 'WIND' resource and a 'view' template. */
  3843.  
  3844. extern pascal Boolean ParseTitleTemplate(StringPtr itsTemplate, short *preDocname, short *constTitle
  3845.    );
  3846.         /* Used in TWindow.IWindow to parse the template for window titles. Returns TRUE if it c
  3847.            hanged
  3848.         the template. preDocname is start of document name in string; constChars is total #
  3849.         characters of window title that are constants. (These values are fixed regardless of the
  3850.         document name.) If preDocname is 0, then the entire title is constant. */
  3851.  
  3852. extern pascal Boolean SubstituteInTitle(StringPtr title, StringPtr newStuff, short preDocname, short
  3853.     constTitle);
  3854.         /* Substitutes newStuff into the template as parsed by ParseTitleTemplate; returns TRUE if a
  3855.         substitution was made. */
  3856.  
  3857.         /* C L I P B O A R D */
  3858.  
  3859. extern pascal void CanPaste(ResType aClipType);
  3860.         /* Call this in your SetUpMenus code to register an ability to paste a particular type of
  3861.         Clipboard data */
  3862.  
  3863. extern pascal OSErr PutDeskScrapData(ResType aResType, Handle aDataHandle);
  3864.         /* Call this from your TCommand method 'WriteToDeskScrap' (for a Command which changes the
  3865.         Clipboard) to write out data to the actual Desk Scrap. The return code from the Scrap
  3866.         Manager is returned as the function value -- will be noErr unless something went wrong.
  3867.         This procedure leaves aDataHandle UNLOCKED. Rather than calling this, you can call the
  3868.         ToolBox routine PutScrap yourself */
  3869.  
  3870.         /* E R R O R S */
  3871.  
  3872. extern pascal void ErrorAlert(OSErr err, long message);
  3873.         /* Displays an error alert box. The message displayed in the alert is constructed base upon
  3874.         err and message, as described in the "Failure Handling" section of the "Cookbook" chapter
  3875.         of the MacApp manual. */
  3876.  
  3877. extern pascal Boolean LookupErrString(short value, short resourceID, StringPtr str);
  3878.         /* Looks up an error value in an 'errs' resource and returns TRUE if found. resourceID s
  3879.            hould
  3880.         be that of a MacApp errs resource; we do the lookup first in errAppTable+resourceID, which
  3881.         applications can use to override or extend the MacApp table. If the value is not found, str
  3882.         will be empty. */
  3883.  
  3884. extern pascal short MacAppAlert(short alertID, Ptr filterProc);
  3885.         /* Does SetCursor(arrow) before calling Alert. */
  3886.  
  3887. extern pascal void StdAlert(short alertID);
  3888.         /* no filterProc, reply ignored */
  3889.  
  3890.         /* V I E W   R E S O U R C E   U T I L I T I E S */
  3891.  
  3892. extern pascal void RegisterStdType(StringPtr typeName, ResType signature);
  3893.         /* Associates the given class with a signature. */
  3894.  
  3895. extern pascal TObject *NewStdObject(ResType signature);
  3896.         /* Returns the prototype object for the given signature. */
  3897.  
  3898. extern pascal ViewRsrcHandle NewViewRsrc(void **p);
  3899.         /* Convenience routine to create a new view resource template handle. Passes back in "p" the
  3900.         pointer to the first template entry. */
  3901.  
  3902. extern pascal void DoneViewRsrc(void *viewRsrc, long lastPtr);
  3903.         /* Cuts back the handle to the proper length, based on lastPtr which should be the addre
  3904.            ss of
  3905.         the next template entry. */
  3906.  
  3907. extern pascal Ptr ExpandPtr(void *viewRsrc, long *p, long offset);
  3908.         /* Bumps size of view resource if necessary to add a new template. Amount to bump is set
  3909.             to at
  3910.         least kViewRsrcExpandAmt over the current size. "p" is offset to point to the next
  3911.         available position for a new template. Returns the old value of p before it was updated. */
  3912.  
  3913. extern pascal Ptr ExpandPtrWStr(void *viewRsrc, long *p, long offset, long len);
  3914.         /* Bumps size of view resource if necessary to add a new template which ends with a
  3915.         variable length string, the length of which is passed in len.
  3916.         Returns the old value of p before it was updated. */
  3917.  
  3918. extern pascal void OffsetPtr(long *p, long offset);
  3919.         /* Adds offset to p, forcing word alignment.*/
  3920.  
  3921. extern pascal void OffsetPtrWStr(long *p, long offset);
  3922.         /* Adds offset to p, taking length of trailing variable length string into account, forcing
  3923.         word alignment.*/
  3924.  
  3925.         /* M I S C E L L A N E O U S */
  3926.  
  3927. extern pascal void ApplicationBeep(void);
  3928.         /* If gApplication is not NIL just calls gApplication.Beep else it does a SysBeep.
  3929.         Removes a circular reference for UFailure.*/
  3930.  
  3931. pascal Boolean CallAlertFilter(GrafPtr theDialog, EventRecord *theEvent, short *itemHit, Ptr 
  3932.    theAlertFilter)
  3933.     =  {0x205F,                                            /* MOVE.L (A7)+,A0 */
  3934. 0x4E90};                                                /* JSR (A0) */
  3935.         /* Lets you call the alert filter specified in theAlertFilter.  Useful for providing
  3936.         your own alert filter behaviour and then passing on to MacApp's */
  3937.  
  3938. extern pascal GrafPtr GetNewCenteredDialog(short dialogID, Ptr dStorage, GrafPtr behind);
  3939.         /* The same as GetNewDialog except it centers the dialog on the screen and sets the curs
  3940.            or to
  3941.         an arrow. */
  3942.  
  3943. extern pascal void GetFocus(FocusRec *theFocusRec);
  3944.         /* gets the current focus into a focusrec. The focusrec.clipRgn must be a valid rgn usef
  3945.            ul for
  3946.         saving and restoring the focus behind MacApp's back.*/
  3947.  
  3948. extern pascal void SetFocus(FocusRec *theFocusRec);
  3949.         /* sets the current focus from a focus rec */
  3950.  
  3951. extern pascal void GetTextStyleFontInfo(TextStyle *theTextStyle, FontInfo *theFontInfo);
  3952.         /* Returns the FontInfo record for the font/face/size specified in theTextStyle.  Uses
  3953.         a temporary port so you don't have to. */
  3954.  
  3955. extern pascal void ExitMacApp(void);
  3956.         /* Call this if for some reason you want to immediately exit the application. It calls
  3957.         gApplication.Terminate, cleans up some other internal stuff, and then calls ExitToShell.
  3958.         (Normally, you would not call this, because MacApp takes care of terminating the
  3959.         application.)*/
  3960.  
  3961. extern pascal void InitUMacApp(short callsToMoreMasters);
  3962.         /* Initialize the UMacApp unit call this in your program after calling: InitToolBox and
  3963.         ValidateConfiguration. */
  3964.  
  3965. extern pascal void InstallIfPrintHandler(TPrintHandler *aPrintHandler, TView *aView);
  3966.         /* Install a clone of aPrintHandler into the view if aPrintHandler is not the
  3967.         same as the null print handler. (Typically if printing is initialized.)  This
  3968.         lets us install a print handler if printing is being used in the application
  3969.         and do NOTHING if it is not. */
  3970.  
  3971. extern pascal Boolean MacAppAlertFilter(GrafPtr theDialog, EventRecord *theEvent, short *itemHit);
  3972.         /* Default alert filter used throughout MacApp.  Lets you answer yes and no to dialogs with
  3973.         keystrokes. Handles "cmd-." and escape. If the alert has not been called in a fa
  3974.    ilure sequence
  3975.         then the application also handles update and activate events and idles. */
  3976.  
  3977. extern pascal RgnHandle MakeNewRgn(void);
  3978.         /* Calls NewRgn, then FailNIL*/
  3979.  
  3980. extern pascal Boolean RectIsVisible(Rect *r);
  3981.         /* Determine if a rect is visible in the current grafport. */
  3982.  
  3983. extern pascal void SetHLPenState(HLState fromHL, HLState toHL);
  3984.         /* Set the pen state for highlighting by XOR, given the highlight transition. You can us
  3985.            e this
  3986.         if you use Paint<X> or Frame<X> or line drawing for your highlighting. */
  3987.         /* ??? Add a pattern parameter or make a helper routine that has a pattern parameter ??? */
  3988.  
  3989. extern pascal void FinderSegProc(void);
  3990.         /* This is a dummy procedure to allow us to find the Finder segment */
  3991.  
  3992. extern pascal void CleanupMacApp(void);
  3993.         /* Called as the final step of TApplication.Run */
  3994. #endif
  3995.  
  3996. extern pascal void VisibleRect(Rect *r);
  3997.         /* Get the currently visible rectangle as defined by thePort clip region */
  3998.  
  3999.